Part Number Hot Search : 
MBM29 N452000 2SK4097 15015 RU3JGF CY14B QPL6216 MC341
Product Description
Full Text Search
 

To Download PIC16F87-EML Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2005 microchip technology inc. ds30487c pic16f87/88 data sheet 18/20/28-pin enhanced flash microcontrollers with nanowatt technology
ds30487c-page ii ? 2005 microchip technology inc. information contained in this publication regarding device applications and the like is provi ded only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. microchip makes no representations or war- ranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip?s products as critical components in life support systems is not authorized except with express written approval by microchip. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic, and smartshunt are registered trademarks of micr ochip technology incorporated in the u.s.a. and other countries. amplab, filterlab, migratable memory, mxdev, mxlab, picmaster, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, mpasm, mplib, mplink, mpsim, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powertool, rflab, rfpicdem, select mode, smart serial, smarttel and total endurance are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2005, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices:  microchip products meet the specification cont ained in their particular microchip data sheet.  microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona and mountain view, california in october 2003. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2005 microchip technology inc. ds30487c-page 1 pic16f87/88 low-power features:  power-managed modes: - primary run: rc oscillator, 76 a, 1 mhz, 2v - rc_run: 7 a, 31.25 khz, 2v - sec_run: 9 a, 32 khz, 2v - sleep: 0.1 a, 2v  timer1 oscillator: 1.8 a, 32 khz, 2v  watchdog timer: 2.2 a, 2v  two-speed oscillator start-up oscillators:  three crystal modes: - lp, xt, hs: up to 20 mhz  two external rc modes  one external clock mode: - ecio: up to 20 mhz  internal oscillator block: - 8 user selectable frequencies: 31 khz, 125 khz, 250 khz, 500 khz, 1 mhz, 2 mhz, 4mhz, 8mhz peripheral features:  capture, compare, pwm (ccp) module: - capture is 16-bit, max. resolution is 12.5 ns - compare is 16-bit, max. resolution is 200 ns - pwm max. resolution is 10-bit  10-bit, 7-channel analog-to-digital converter  synchronous serial port (ssp) with spi? (master/slave) and i 2 c? (slave)  addressable universal synchronous asynchronous receiver transmitter (ausart/sci) with 9-bit address detection: - rs-232 operation using internal oscillator (no external crystal required)  dual analog comparator module: - programmable on-chip voltage reference - programmable input multiplexing from device inputs and internal voltage reference - comparator outputs are externally accessible pin diagram special microcontroller features:  100,000 erase/write cycles enhanced flash program memory typical  1,000,000 typical erase/write cycles eeprom data memory typical  eeprom data retention: > 40 years  in-circuit serial programming? (icsp?) via two pins  processor read/write access to program memory  low-voltage programming  in-circuit debugging via two pins  extended watchdog timer (wdt): - programmable period from 1 ms to 268s  wide operating voltage range: 2.0v to 5.5v ra1/an1 ra0/an0 ra7/osc1/clki ra6/osc2/clko v dd rb7/an6/pgd/ rb6/an5/pgc/ rb5/ss /tx/ck rb4/sck/scl ra3/an3/v ref +/ ra4/an4/t0cki/ ra5/mclr /v pp v ss rb0/int/ccp1 (1) rb1/sdi/sda rb2/sdo/rx/dt rb3/pgm/ccp1 (1) 1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10 pic16f88 t1osi t1oso/t1cki c2out c1out v ref - ra2/an2/cv ref / 18-pin pdip, soic note 1: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register. device program memory data memory i/o pins 10-bit a/d (ch) ccp (pwm) ausart comparators ssp timers 8/16-bit flash (bytes) # single-word instructions sram (bytes) eeprom (bytes) pic16f87 7168 4096 368 256 16 n/a 1 y 2 y 2/1 pic16f88 7168 4096 368 256 16 1 1 y 2 y 2/1 18/20/28-pin enhanced flash mcus with nanowatt technology
pic16f87/88 ds30487c-page 2 ? 2005 microchip technology inc. pin diagrams ra1/an1 ra0/an0 ra7/osc1/clki ra6/osc2/clko v dd rb7/pgd/t1osi rb6/pgc/t1oso/t1cki rb5/ss /tx/ck rb4/sck/scl ra2/an2/cv ref ra3/an3/c1out ra4/t0cki/c2out ra5/mclr /v pp v ss rb0/int/ccp1 (1) rb1/sdi/sda rb2/sdo/rx/dt rb3/pgm/ccp1 (1) 1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10 pic16f87 18-pin pdip, soic rb7/an6/pgd/t1osi rb6/an5/pgc/t1oso/t1cki ra7/osc1/clki ra6/osc2/clko v dd rb5/ss /tx/ck rb4/sck/scl rb3/pgm/ccp1 (1) rb2/sdo/rx/dt ra0/an0 ra1/an1 ra4/an4/t0cki/c2out ra5/mclr 1/v pp v ss ra2/an2/cv ref /v ref - ra3/an3/v ref +/c1out rb0/int/ccp1 (1) rb1/sdi/sda 1 2 3 4 5 6 7 8 9 20 19 18 17 16 15 14 13 12 v dd v ss 10 11 pic16f88 20-pin ssop 20-pin ssop 18-pin pdip, soic ra1/an1 ra0/an0 ra7/osc1/clki ra6/osc2/clko v dd rb7/an6/pgd/t1osi rb6/an5/pgc/t1oso/t1cki rb5/ss /tx/ck rb4/sck/scl ra2/an2/cv ref /v ref - ra3/an3/v ref +/c1out ra4/an4/t0cki/c2out ra5/mclr /v pp v ss rb0/int/ccp1 (1) rb1/sdi/sda rb2/sdo/rx/dt rb3/pgm/ccp1 (1) 1 2 3 4 5 6 7 8 9 18 17 16 15 14 13 12 11 10 pic16f88 rb7/pgd/t1osi rb6/pgc/t1oso/t1cki ra7/osc1/clki ra6/osc2/clko v dd rb5/ss /tx/ck rb4/sck/scl rb3/pgm/ccp1 (1) rb2/sdo/rx/dt ra0/an0 ra1/an1 ra4/t0cki/c2out ra5/mclr /v pp v ss ra2/an2/cv ref ra3/an3/c1out rb0/int/ccp1 (1) rb1/sdi/sda 1 2 3 4 5 6 7 8 9 20 19 18 17 16 15 14 13 12 v dd v ss 10 11 pic16f87 note 1: the ccp1 pin is determined by the ccpmx bi t in configuration word 1 register.
? 2005 microchip technology inc. ds30487c-page 3 pic16f87/88 pin diagrams (cont?d) 16 2 ra2/an2/cv ref ra0/an0 ra4/t0cki/c2out ra5/mclr /v pp nc v ss nc rb0/int/ccp1 (1) rb1/sdi/sda ra3/an3/c1out ra7/osc1/clki ra6/osc2/clko v dd nc v dd rb7/pgd/t1osi rb6/pgc/t1oso/t1cki rb5/ss /tx/ck rb4/sck/scl 7 pic16f87 1 3 6 5 4 15 21 19 20 17 18 22 28 26 27 23 24 25 14 8 10 9 13 12 11 v ss nc nc ra1/an1 rb2/sdo/rx/dt rb3/pgm/ccp1 (1) nc nc nc 16 2 ra2/an2/cv ref /v ref - ra0/an0 ra4/an4/t0cki/c2out ra5/mclr /v pp nc v ss nc rb0/int/ccp1 (1) rb1/sdi/sda ra3/an3/v ref +/c1out ra7/osc1/clki ra6/osc2/clko v dd nc v dd rb7/an6/pgd/t1osi rb6/an5/pgc/t1oso/t1cki rb5/ss /tx/ck rb4/sck/scl 7 pic16f88 1 3 6 5 4 15 21 19 20 17 18 22 28 26 27 23 24 25 14 8 10 9 13 12 11 v ss nc nc ra1/an1 rb2/sdo/rx/dt rb3/pgm/ccp1 (1) nc nc nc 28-pin qfn 28-pin qfn note 1: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register.
pic16f87/88 ds30487c-page 4 ? 2005 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 5 2.0 memory organization ......................................................................................................... ........................................................ 11 3.0 data eeprom and flash program memory........................................................................................ ...................................... 27 4.0 oscillator configurations ................................................................................................... ......................................................... 35 5.0 i/o ports ................................................................................................................... .................................................................. 51 6.0 timer0 module ............................................................................................................... ............................................................ 67 7.0 timer1 module ............................................................................................................... ............................................................ 71 8.0 timer2 module ............................................................................................................... ............................................................ 79 9.0 capture/compare/pwm (ccp) module ............................................................................................ ......................................... 81 10.0 synchronous serial port (ssp) module ....................................................................................... .............................................. 87 11.0 addressable universal synchronous asynchr onous receiver transmitter (ausart) ............................................... .............. 97 12.0 analog-to-digital converter (a/d) module ................................................................................... ............................................. 113 13.0 comparator module.......................................................................................................... ........................................................ 121 14.0 comparator voltage reference module ........................................................................................ ........................................... 127 15.0 special features of the cpu ................................................................................................ .................................................... 129 16.0 instruction set summary .................................................................................................... ...................................................... 149 17.0 development support........................................................................................................ ....................................................... 157 18.0 electrical characteristics ................................................................................................. ......................................................... 163 19.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 193 20.0 packaging information...................................................................................................... ........................................................ 207 appendix a: revision history................................................................................................... .......................................................... 213 appendix b: device differences................................................................................................. ........................................................ 213 index .......................................................................................................................... ........................................................................ 215 the microchip web site ......................................................................................................... ............................................................ 223 customer change notification service ........................................................................................... ................................................... 223 customer support ............................................................................................................... ............................................................... 223 reader response ................................................................................................................ .............................................................. 224 pic16f87/88 product identification system ...................................................................................... ................................................ 225 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following:  microchip?s worldwide web site; http://www.microchip.com  your local microchip sales office (see last page) when contacting a sales office, please spec ify which device, revision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
? 2005 microchip technology inc. ds30487c-page 5 pic16f87/88 1.0 device overview this document contains device specific information for the operation of the pic16f87/88 devices. additional information may be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023) which may be downloaded from the microchip web site. this reference manual should be considered a comple- mentary document to this data sheet and is highly recommended reading for a better understanding of the device architecture and operation of the peripheral modules. the pic16f87/88 belongs to the mid-range family of the picmicro ? devices. block diagrams of the devices are shown in figure 1-1 and figure 1-2. these devices contain features that are new to the pic16 product line:  low-power modes: rc_run allows the core and peripherals to be clocked from the intrc, while sec_run allows the core and peripherals to be clocked from the low-power timer1. refer to section 4.7 ?power-managed modes? for further details.  internal rc oscillator with eight selectable frequencies, including 31.25 khz, 125 khz, 250 khz, 500 khz, 1 mhz, 2 mhz, 4 mhz and 8 mhz. the intrc can be configured as a primary or secondary clock source. refer to section 4.5 ?internal oscillator block? for further details.  the timer1 module current consumption has been greatly reduced from 20 a (previous pic16 devices) to 1.8 a typical (32 khz at 2v), which is ideal for real-time clock applications. refer to section 7.0 ?timer1 module? for further details.  extended watchdog timer (wdt) that can have a programmable period from 1 ms to 268s. the wdt has its own 16-bit prescaler. refer to section 15.12 ?watchdog timer (wdt)? for further details.  two-speed start-up: when the oscillator is configured for lp, xt or hs oscillator mode, this feature will clock the device from the intrc while the oscillator is warming up. this, in turn, will enable almost immediate code execution. refer to section 15.12.3 ?two-speed clock start-up mode? for further details.  fail-safe clock monitor: this feature will allow the device to continue operation if the primary or secondary clock source fails by switching over to the intrc.  the a/d module has a new register for pic16 devices named ansel. this register allows easier configuration of analog or digital i/o pins. table 1-1: available memory in pic16f87/88 devices there are 16 i/o pins that are user configurable on a pin-to-pin basis. some pins are multiplexed with other device functions. these functions include:  external interrupt  change on portb interrupt  timer0 clock input  low-power timer1 clock/oscillator  capture/compare/pwm  10-bit, 7-channel a/d converter (pic16f88 only)  spi?/i 2 c?  two analog comparators  ausart mclr (ra5) can be configured as an input table 1-2 details the pinout of the devices with descriptions and details for each pin. device program flash data memory data eeprom pic16f87/88 4k x 14 368 x 8 256 x 8
pic16f87/88 ds30487c-page 6 ? 2005 microchip technology inc. figure 1-1: pic16f87 device block diagram program memory 4k x 14 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers 368 x 8 direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clki osc2/clko ra5/mclr v dd , v ss 8 8 brown-out reset note 1: higher order bits are from the status register. 2: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register. 8 3 comparators timer0 data ee 256 bytes timer1 ccp1 timer2 ausart porta portb ra4/t0cki/c2out rb0/int/ccp1 (2) ra3/an3/c1out ra2/an2/cv ref ra1/an1 ra0/an0 ra5/mclr /v pp ra6/osc2/clko rb5/ss /tx/ck rb4/sck/scl rb3/pgm/ccp1 (2) rb2/sdo/rx/dt rb1/sdi/sda rb6/pgc/t1oso/t1cki rb7/pgd/t1osi ra7/osc1/clki ssp flash
? 2005 microchip technology inc. ds30487c-page 7 pic16f87/88 figure 1-2: pic16f88 device block diagram flash program memory 4k x 14 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers 368 x 8 direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clki osc2/clko ra5/mclr v dd , v ss 8 8 brown-out reset note 1: higher order bits are from the status register. 2: the ccp1 pin is determined by the ccpmx bi t in configuration word 1 register. 8 3 comparators timer0 data ee 256 bytes timer1 ccp1 timer2 ausart porta portb ra4/an4/t0cki/c2out rb0/int/ccp1 (2) ra3/an3/v ref +/c1out ra2/an2/cv ref /v ref - ra1/an1 ra0/an0 ra5/mclr /v pp ra6/osc2/clko rb5/ss /tx/ck rb4/sck/scl rb3/pgm/ccp1 (2) rb2/sdo/rx/dt rb1/sdi/sda rb6/an5/pgc/t1oso/t1cki rb7/an6/pgd/t1osi ra7/osc1/clki 10-bit a/d ssp
pic16f87/88 ds30487c-page 8 ? 2005 microchip technology inc. table 1-2: pic16f87/88 pinout description pin name pdip/ soic pin# ssop pin# qfn pin# i/o/p type buffer ty pe description porta is a bidirectional i/o port. ra0/an0 ra0 an0 17 19 23 i/o i ttl analog bidirectional i/o pin. analog input channel 0. ra1/an1 ra1 an1 18 20 24 i/o i ttl analog bidirectional i/o pin. analog input channel 1. ra2/an2/cv ref /v ref - ra2 an2 cv ref v ref - (4) 1126 i/o i o i ttl analog analog bidirectional i/o pin. analog input channel 2. comparator v ref output. a/d reference voltage (low) input. ra3/an3/v ref +/c1out ra3 an3 v ref + (4) c1out 2227 i/o i i o ttl analog analog bidirectional i/o pin. analog input channel 3. a/d reference voltage (high) input. comparator 1 output. ra4/an4/t0cki/c2out ra4 an4 (4) t0cki c2out 3328 i/o i i o st analog st bidirectional i/o pin. analog input channel 4. clock input to the tmr0 timer/counter. comparator 2 output. ra5/mclr /v pp ra5 mclr v pp 441 i i p st st ? input pin. master clear (reset). input/programming voltage input. this pin is an active-low reset to the device. programming voltage input. ra6/osc2/clko ra6 osc2 clko 15 17 20 i/o o o st ? ? bidirectional i/o pin. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, this pin outputs clko signal which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. ra7/osc1/clki ra7 osc1 clki 16 18 21 i/o i i st st/cmos (3) ? bidirectional i/o pin. oscillator crystal input. external clock source input. legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input w hen configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: this buffer is a schmitt trigger input when confi gured in rc oscillator mode and a cmos input otherwise. 4: pic16f88 devices only. 5: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register.
? 2005 microchip technology inc. ds30487c-page 9 pic16f87/88 portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-up on all inputs. rb0/int/ccp1 (5) rb0 int ccp1 677 i/o i i/o ttl st (1) st bidirectional i/o pin. external interrupt pin. capture input, compare output, pwm output. rb1/sdi/sda rb1 sdi sda 788 i/o i i/o ttl st st bidirectional i/o pin. spi? data in. i 2 c? data. rb2/sdo/rx/dt rb2 sdo rx dt 899 i/o o i i/o ttl st bidirectional i/o pin. spi data out. ausart asynchronous receive. ausart synchronous detect. rb3/pgm/ccp1 (5) rb3 pgm ccp1 91010 i/o i/o i ttl st st bidirectional i/o pin. low-voltage icsp? programming enable pin. capture input, compare output, pwm output. rb4/sck/scl rb4 sck scl 10 11 12 i/o i/o i ttl st st bidirectional i/o pin. interrupt-on-change pin. synchronous serial clock input/output for spi. synchronous serial clock input for i 2 c. rb5/ss /tx/ck rb5 ss tx ck 11 12 13 i/o i o i/o ttl ttl bidirectional i/o pin. interrupt-on-change pin. slave select for spi in slave mode. ausart asynchronous transmit. ausart synchronous clock. rb6/an5/pgc/t1oso/ t1cki rb6 an5 (4) pgc t1oso t1cki 12 13 15 i/o i i/o o i ttl st (2) st st bidirectional i/o pin. interrupt-on-change pin. analog input channel 5. in-circuit debugger and programming clock pin. timer1 oscillator output. timer1 external clock input. rb7/an6/pgd/t1osi rb7 an6 (4) pgd t1osi 13 14 16 i/o i i i ttl st (2) st bidirectional i/o pin. interrupt-on-change pin. analog input channel 6. in-circuit debugger and icsp programming data pin. timer1 oscillator input. v ss 5 5, 6 3, 5 p ? ground reference for logic and i/o pins. v dd 14 15, 16 17, 19 p ? positive supply for logic and i/o pins. table 1-2: pic16f87/88 pinout description (continued) pin name pdip/ soic pin# ssop pin# qfn pin# i/o/p type buffer type description legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input w hen configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: this buffer is a schmitt trigger input when confi gured in rc oscillator mode and a cmos input otherwise. 4: pic16f88 devices only. 5: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register.
pic16f87/88 ds30487c-page 10 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 11 pic16f87/88 2.0 memory organization there are two memory blocks in the pic16f87/88 devices. these are the program memory and the data memory. each block has its own bus, so access to each block can occur during the same oscillator cycle. the data memory can be further broken down into the general purpose ram and the special function registers (sfrs). the operation of the sfrs that control the ?core? are described here. the sfrs used to control the peripheral modules are described in the section discussing each individual peripheral module. the data memory area also contains the data eeprom memory. this memory is not directly mapped into the data memory but is indirectly mapped. that is, an indi- rect address pointer specifies the address of the data eeprom memory to read/write. the pic16f87/88 device?s 256 bytes of data eeprom memory have the address range of 00h-ffh. more details on the eeprom memory can be found in section 3.0 ?data eeprom and flash program memory? . additional information on device memory may be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023). 2.1 program memory organization the pic16f87/88 devices have a 13-bit program counter capable of addressing an 8k x 14 program memory space. for the pic16f87/88, the first 4k x 14 (0000h-0fffh) is physically implemented (see figure 2-1). accessing a location above the physically implemented address will cause a wraparound. for example, the same instruction will be accessed at locations 020h, 420h, 820h, c20h, 1020h, 1420h, 1820h and 1c20h. the reset vector is at 0000h and the interrupt vector is at 0004h. figure 2-1: program memory map and stack: pic16f87/88 2.2 data memory organization the data memory is partitioned into multiple banks that contain the general purpose registers and the special function registers. bits rp1 (status<6>) and rp0 (status<5>) are the bank select bits. each bank extends up to 7fh (128 bytes). the lower locations of each bank are reserved for the special function registers. above the special function regis- ters are general purpose registers, implemented as static ram. all implemented banks contain sfrs. some ?high use? sfrs from one bank may be mirrored in another bank for code reduction and quicker access (e.g., the status register is in banks 0-3). rp1:rp0 bank 00 0 01 1 10 2 11 3 note: eeprom data memory description can be found in section 3.0 ?data eeprom and flash program memory? of this data sheet. pc<12:0> 13 0000h 0004h 0005h stack level 1 stack level 8 reset vector interrupt vector on-chip call, return retfie, retlw 1fffh stack level 2 program memory page 0 07ffh wraps to 0000h-03ffh page 1 0fffh 1000h 0800h
pic16f87/88 ds30487c-page 12 ? 2005 microchip technology inc. 2.2.1 general purpose register file the register file can be accessed either directly, or indirectly, through the file select register (fsr). figure 2-2: pic16f87 register file map indirect addr. (*) tmr0 pcl status fsr porta portb pclath intcon pir1 option_reg pcl status fsr trisa trisb pclath intcon pie1 pcon 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1ch 1dh 1eh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 unimplemented data memory locations, read as ? 0 ?. * not a physical register. note 1: this register is reserved, maintain this register clear. file address indirect addr. (*) indirect addr. (*) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh indirect addr. (*) cvrcon tmr0 option_reg pir2 pie2 general purpose register accesses 70h-7fh trisb portb 96 bytes efh f0h 10ch 10dh 10eh 10fh 110h 18ch 18dh 18eh 18fh 190h eedata eeadr eecon1 eecon2 eedath eeadrh reserved (1) reserved (1) 17fh 1ffh bank 2 bank 3 19fh 1a0h accesses 70h-7fh 11fh 120h accesses 70h-7fh cmcon osccon general purpose register 80 bytes tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h ccp1con rcsta txreg rcreg pr2 txsta spbrg osctune wdtcon 16fh 170h general purpose register 80 bytes 1efh 1f0h general purpose register 80 bytes general purpose register 16 bytes general purpose register 16 bytes sspbuf sspcon sspadd sspstat file address file address file address status
? 2005 microchip technology inc. ds30487c-page 13 pic16f87/88 figure 2-3: pic16f88 register file map indirect addr. (*) tmr0 pcl status fsr porta portb pclath intcon pir1 option_reg pcl status fsr trisa trisb pclath intcon pie1 pcon 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1ch 1dh 1eh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 file address indirect addr. (*) indirect addr. (*) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh indirect addr. (*) tmr0 option_reg pir2 pie2 adresh adcon0 adcon1 general purpose register accesses 70h-7fh trisb portb 96 bytes 10ch 10dh 10eh 10fh 110h 18ch 18dh 18eh 18fh 190h eedata eeadr eecon1 eecon2 eedath eeadrh reserved (1) reserved (1) 17fh 1ffh bank 2 bank 3 19fh 1a0h 11fh 120h cvrcon osccon cmcon adresl tmr1l tmr1h t1con tmr2 ccpr1l ccpr1h ccp1con rcsta txreg rcreg pr2 txsta spbrg t2con osctune wdtcon efh f0h general purpose register 80 bytes 16fh 170h general purpose register 80 bytes 1efh 1f0h general purpose register 80 bytes general purpose register 16 bytes general purpose register 16 bytes accesses 70h-7fh accesses 70h-7fh sspbuf sspcon sspadd sspstat ansel file address file address file address unimplemented data memory locations, read as ? 0 ?. * not a physical register. note 1: this register is reserved, maintain this register clear.
pic16f87/88 ds30487c-page 14 ? 2005 microchip technology inc. 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. a list of these registers is given in table 2-1. the special function registers can be classified into two sets: core (cpu) and peripheral. those registers associated with the core functions are described in detail in this section. those related to the operation of the peripheral features are described in detail in the peripheral feature section. table 2-1: special function register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page bank 0 00h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 26, 135 01h tmr0 timer0 module register xxxx xxxx 69 02h (2) pcl program counter (pc) least significant byte 0000 0000 03h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 17 04h (2) fsr indirect data memory address pointer xxxx xxxx 135 05h porta porta data latch when written; porta pins when read (pic16f87) porta data latch when written; porta pins when read (pic16f88) xxxx 0000 xxx0 0000 52 06h portb portb data latch when written; portb pins when read (pic16f87) portb data latch when written; portb pins when read (pic16f88) xxxx xxxx 00xx xxxx 58 07h ? unimplemented ? ? 08h ? unimplemented ? ? 09h ? unimplemented ? ? 0ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 135 0bh (2) intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 19, 69, 77 0ch pir1 ?adif (4) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 21, 77 0dh pir2 osfif cmif ? eeif ? ? ? ? 00-0 ---- 23, 34 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx 77, 83 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx 77, 83 10h t1con ? t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on -000 0000 72, 83 11h tmr2 timer2 module register 0000 0000 80, 85 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 80, 85 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx 90, 95 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 89, 95 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx 83, 85 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx 83, 85 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 81, 83 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 98, 99 19h txreg ausart transmit data register 0000 0000 103 1ah rcreg ausart receive data register 0000 0000 105 1bh ? unimplemented ? ? 1ch ? unimplemented ? ? 1dh ? unimplemented ? ? 1eh adresh (4) a/d result register high byte xxxx xxxx 120 1fh adcon0 (4) adcs1 adcs0 chs2 chs1 chs0 go/done ?adon 0000 00-0 114, 120 legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: ra5 is an input only; the state of the trisa5 bit has no effect and will always read ? 1 ?. 4: pic16f88 device only.
? 2005 microchip technology inc. ds30487c-page 15 pic16f87/88 bank 1 80h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 26, 135 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 18, 69 82h (2) pcl program counter (pc) least significant byte 0000 0000 135 83h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 17 84h (2) fsr indirect data memory address pointer xxxx xxxx 135 85h trisa trisa7 trisa6 trisa5 (3) porta data direction register (trisa<4:0>) 1111 1111 52, 126 86h trisb portb data direction register 1111 1111 58, 85 87h ? unimplemented ? ? 88h ? unimplemented ? ? 89h ? unimplemented ? ? 8ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 135 8bh (2) intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 19, 69, 77 8ch pie1 ? adie (4) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 20, 80 8dh pie2 osfie cmie ?eeie ? ? ? ? 00-0 ---- 22, 34 8eh pcon ? ? ? ? ? ?por bor ---- --0q 24 8fh osccon ? ircf2 ircf1 ircf0 osts iofs scs1 scs0 -000 0000 40 90h osctune ? ? tun5 tun4 tun3 tun2 tun1 tun0 --00 0000 38 91h ? unimplemented ? ? 92h pr2 timer2 period register 1111 1111 80, 85 93h sspadd synchronous serial port (i 2 c? mode) address register 0000 0000 95 94h sspstat smp cke d/a psr/w ua bf 0000 0000 88, 95 95h ? unimplemented ? ? 96h ? unimplemented ? ? 97h ? unimplemented ? ? 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 97, 99 99h spbrg baud rate generator register 0000 0000 99, 103 9ah ? unimplemented ? ? 9bh ansel (4) ? ans6 ans5 ans4 ans3 ans2 ans1 ans0 -111 1111 120 9ch cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0111 121, 126, 128 9dh cvrcon cvren cvroe cvrr ? cvr3 cvr2 cvr1 cvr0 000- 0000 126, 128 9eh adresl (4) a/d result register low byte xxxx xxxx 120 9fh adcon1 (4) adfm adcs2 vcfg1 vcfg0 ? ? ? ? 0000 ---- 52, 115, 120 table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: ra5 is an input only; the state of the trisa5 bit has no effect and will always read ? 1 ?. 4: pic16f88 device only.
pic16f87/88 ds30487c-page 16 ? 2005 microchip technology inc. bank 2 100h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 26, 135 101h tmr0 timer0 module register xxxx xxxx 69 102h (2) pcl program counter?s (pc) least significant byte 0000 0000 135 103h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 17 104h (2) fsr indirect data memory address pointer xxxx xxxx 135 105h wdtcon ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten ---0 1000 142 106h portb portb data latch when written; portb pins when read (pic16f87) portb data latch when written; portb pins when read (pic16f88) xxxx xxxx 00xx xxxx 58 107h ? unimplemented ? ? 108h ? unimplemented ? ? 109h ? unimplemented ? ? 10ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 135 10bh (2) intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 19, 69, 77 10ch eedata eeprom/flash data register low byte xxxx xxxx 34 10dh eeadr eeprom/flash address register low byte xxxx xxxx 34 10eh eedath ? ? eeprom/flash data register high byte --xx xxxx 34 10fh eeadrh ? ? ? ? eeprom/flash address register high byte ---- xxxx 34 bank 3 180h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 135 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 18, 69 182h (2) pcl program counter (pc) least significant byte 0000 0000 135 183h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 17 184h (2) fsr indirect data memory address pointer xxxx xxxx 135 185h ? unimplemented ? ? 186h trisb portb data direction register 1111 1111 58, 83 187h ? unimplemented ? ? 188h ? unimplemented ? ? 189h ? unimplemented ? ? 18ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 135 18bh (2) intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 19, 69, 77 18ch eecon1 eepgd ? ? free wrerr wren wr rd x--x x000 28, 34 18dh eecon2 eeprom control register 2 (not a physical register) ---- ---- 34 18eh ? reserved, maintain clear 0000 0000 ? 18fh ? reserved, maintain clear 0000 0000 ? table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ? 0 ?, r = reserved. shaded locations are unimplemented, read as ? 0 ?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for pc<12:8>, whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: ra5 is an input only; the state of the trisa5 bit has no effect and will always read ? 1 ?. 4: pic16f88 device only.
? 2005 microchip technology inc. ds30487c-page 17 pic16f87/88 2.2.2.1 status register the status register, shown in register 2-1, contains the arithmetic status of the alu, the reset status and the bank select bits for data memory. the status register can be the destination for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as ? 000u u1uu ? (where u = unchanged). it is recommended, therefore, that only bcf , bsf , swapf and movwf instructions are used to alter the status register because these instructions do not affect the z, c or dc bits from the status register. for other instructions not affecting any status bits, see section 16.0 ?instruction set summary? . register 2-1: status: arithmetic status register (address 03h, 83h, 103h, 183h) note: the c and dc bits operate as a borrow and digit borrow bit, respectively, in subtraction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdc c bit 7 bit 0 bit 7 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h-1ffh) 0 = bank 0, 1 (00h-ffh) bit 6-5 rp<1:0>: register bank select bits (used for direct addressing) 11 = bank 3 (180h-1ffh) 10 = bank 2 (100h-17fh) 01 = bank 1 (80h-ffh) 00 = bank 0 (00h-7fh) each bank is 128 bytes. bit 4 to : time-out bit 1 = after power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit ( addwf , addlw , sublw and subwf instructions) (1) 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit ( addwf , addlw , sublw and subwf instructions) (1,2) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow, the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. 2: for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 18 ? 2005 microchip technology inc. 2.2.2.2 option_reg register the option_reg register is a readable and writable register that contains various control bits to configure the tmr0 prescaler/wdt postscaler (single assign- able register known also as the prescaler), the external int interrupt, tmr0 and the weak pull-ups on portb. register 2-2: option_reg: option control register (address 81h, 181h) note: to achieve a 1:1 prescaler assignment for the tmr0 register, assign the prescaler to the watchdog timer. although the pres- caler can be assigned to either the wdt or timer0, but not both, a new divide counter is implemented in the wdt circuit to give multiple wdt time-out selections. this allows tmr0 and wdt to each have their own scaler. refer to section 15.12 ?watchdog timer (wdt)? for further details. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of rb0/int pin 0 = interrupt on falling edge of rb0/int pin bit 5 t0cs: tmr0 clock source select bit 1 = transition on ra4/t0cki/c2out pin 0 = internal instruction cycle clock (clko) bit 4 t0se: tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/t0cki/c2out pin 0 = increment on low-to-high transition on ra4/t0cki/c2out pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit value tmr0 rate wdt rate 000 1 : 2 1 : 1 001 1 : 4 1 : 2 010 1 : 8 1 : 4 011 1 : 16 1 : 8 100 1 : 32 1 : 16 101 1 : 64 1 : 32 110 1 : 128 1 : 64 111 1 : 256 1 : 128
? 2005 microchip technology inc. ds30487c-page 19 pic16f87/88 2.2.2.3 intcon register the intcon register is a readable and writable regis- ter that contains various enable and flag bits for the tmr0 register overflow, rb port change and external rb0/int pin interrupts. register 2-3: intcon: interrupt control register ( address 0bh, 8bh, 10bh, 18bh) note: interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie tmr0ie int0ie rbie tmr0if int0if rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie: peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 int0ie: rb0/int external interrupt enable bit 1 = enables the rb0/int external interrupt 0 = disables the rb0/int external interrupt bit 3 rbie: rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 int0if: rb0/int external interrupt flag bit 1 = the rb0/int external interrupt occurred (must be cleared in software) 0 = the rb0/int external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. 1 = at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 20 ? 2005 microchip technology inc. 2.2.2.4 pie1 register this register contains the individual enable bits for the peripheral interrupts. register 2-4: pie1: peripheral interrupt enable register 1 (address 8ch) note: bit peie (intcon<6>) must be set to enable any peripheral interrupt. u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ?adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 adie: a/d converter interrupt enable bit (1) 1 = enabled 0 = disabled note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. bit 5 rcie: ausart receive interrupt enable bit 1 = enabled 0 = disabled bit 4 txie: ausart transmit interrupt enable bit 1 = enabled 0 = disabled bit 3 sspie: synchronous serial port (ssp) interrupt enable bit 1 = enabled 0 = disabled bit 2 ccp1ie: ccp1 interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enabled 0 = disabled bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enabled 0 = disabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 21 pic16f87/88 2.2.2.5 pir1 register this register contains the individual flag bits for the peripheral interrupts. register 2-5: pir1: peripheral interrupt request (flag) register 1 (address 0ch) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit, or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. u-0 r/w-0 r-0 r-0 r-0 r/w-0 r/w-0 r/w-0 ?adif (1) rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 adif: a/d converter interrupt flag bit (1) 1 = the a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. bit 5 rcif: ausart receive interrupt flag bit 1 = the ausart receive buffer is full (cleared by reading rcreg) 0 = the ausart receive buffer is not full bit 4 txif: ausart transmit interrupt flag bit 1 = the ausart transmit buffer is empty (cleared by writing to txreg) 0 = the ausart transmit buffer is full bit 3 sspif: synchronous serial port (ssp) interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if: ccp1 interrupt flag bit capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode. bit 1 tmr2if: tmr2 to pr2 interrupt flag bit 1 = a tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = the tmr1 register overflowed (must be cleared in software) 0 = the tmr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 22 ? 2005 microchip technology inc. 2.2.2.6 pie2 register the pie2 register contains the individual enable bit for the eeprom write operation interrupt. register 2-6: pie2: peripheral interrupt enable register 2 (address 8dh) r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 osfie cmie ? eeie ? ? ? ? bit 7 bit 0 bit 7 osfie: oscillator fail interrupt enable bit 1 = enabled 0 = disabled bit 6 cmie: comparator interrupt enable bit 1 = enabled 0 = disabled bit 5 unimplemented: read as ? 0 ? bit 4 eeie: eeprom write operation interrupt enable bit 1 = enabled 0 = disabled bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 23 pic16f87/88 2.2.2.7 pir2 register the pir2 register contains the flag bit for the eeprom write operation interrupt. . register 2-7: pir2: peripheral interrupt request (flag) register 2 (address 0dh) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit, or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 osfif cmif ? eeif ? ? ? ? bit 7 bit 0 bit 7 osfif: oscillator fail interrupt flag bit 1 = system oscillator failed, clock input has changed to intrc (must be cleared in software) 0 = system clock operating bit 6 cmif: comparator interrupt flag bit 1 = comparator input has changed (must be cleared in software) 0 = comparator input has not changed bit 5 unimplemented: read as ? 0 ? bit 4 eeif: eeprom write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation is not complete or has not been started bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 24 ? 2005 microchip technology inc. 2.2.2.8 pcon register the power control (pcon) register contains a flag bit to allow differentiation between a power-on reset (por), a brown-out reset, an external mclr reset and wdt reset. register 2-8: pcon: power control regist er (address 8eh) note: interrupt flag bits get set when an interrupt condition occurs, regardless of the state of its corresponding enable bit, or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. note: bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor is clear, indicating a brown-out has occurred. the bor status bit is a ?don?t care? and is not necessarily predictable if the brown- out circuit is disabled (by clearing the boren bit in the configuration word register). u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-x ? ? ? ? ? ?por bor bit 7 bit 0 bit 7-2 unimplemented: read as ? 0 ? bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 25 pic16f87/88 2.3 pcl and pclath the program counter (pc) is 13 bits wide. the low byte comes from the pcl register which is a readable and writable register. the upper bits (pc<12:8>) are not readable but are indirectly writable through the pclath register. on any reset, the upper bits of the pc will be cleared. figure 2-4 shows the two situations for the loading of the pc. the upper example in the figure shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in the figure shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 2-4: loading of pc in different situations 2.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when doing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note, an556, ?implementing a table read? . 2.3.2 stack the pic16f87/88 family has an 8-level deep x 13-bit wide hardware stack. the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return, retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 program memory paging all pic16f87/88 devices are capable of addressing a continuous 8k word block of program memory. the call and goto instructions provide only 11 bits of address to allow branching within any 2k program memory page. when doing a call or goto instruction, the upper 2 bits of the address are provided by pclath<4:3>. when doing a call or goto instruc- tion, the user must ensure that the page select bits are programmed so that the desired program memory page is addressed. if a return from a call instruction (or interrupt) is executed, the entire 13-bit pc is popped off the stack. therefore, manipulation of the pclath<4:3> bits is not required for the return instructions (which pops the address from the stack). example 2-1 shows the calling of a subroutine in page 1 of the program memory. this example assumes that pclath is saved and restored by the interrupt service routine (if interrupts are used). example 2-1: call of a subroutine in page 1 from page 0 pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu goto,call opcode <10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch 87 2 pclath pch pcl pcl as destination pcl note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call, return, retlw and retfie instructions, or the vectoring to an interrupt address. note: the contents of the pclath register are unchanged after a return or retfie instruction is executed. the user must rewrite the contents of the pclath regis- ter for any subsequent subroutine calls or goto instructions. org 0x500 bcf pclath, 4 bsf pclath, 3 ;select page 1 ;(800h-fffh) call sub1_p1 ;call subroutine in : ;page 1 (800h-fffh) : org 0x900 ;page 1 (800h-fffh) sub1_p1 : ;called subroutine ;page 1 (800h-fffh) : return ;return to ;call subroutine ;in page 0 ;(000h-7ffh)
pic16f87/88 ds30487c-page 26 ? 2005 microchip technology inc. 2.5 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf reg- ister. any instruction using the indf register actually accesses the register pointed to by the file select reg- ister, fsr. reading the indf register itself, indirectly (fsr = 0 ) will read 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 2-5. a simple program to clear ram locations 20h-2fh using indirect addressing is shown in example 2-2. example 2-2: indirect addressing figure 2-5: direct/indirect addressing movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr, f ;inc pointer btfss fsr, 4 ;all done? goto next ;no clear next continue : ;yes continue note 1: for register file map detail, see figure 2-2 or figure 2-3. data memory (1) indirect addressing direct addressing bank select location select rp1:rp0 6 0 from opcode irp fsr register 7 0 bank select location select 00 01 10 11 bank 0 bank 1 bank 2 bank 3 ffh 80h 7fh 00h 17fh 100h 1ffh 180h
? 2005 microchip technology inc. ds30487c-page 27 pic16f87/88 3.0 data eeprom and flash program memory the data eeprom and flash program memory are readable and writable during normal operation (over the full v dd range). this memory is not directly mapped in the register file space. instead, it is indirectly addressed through the special function registers. there are six sfrs used to read and write this memory:  eecon1  eecon2  eedata  eedath  eeadr  eeadrh this section focuses on reading and writing data eeprom and flash program memory during normal operation. refer to the appropriate device program- ming specification document for serial programming information. when interfacing the data memory block, eedata holds the 8-bit data for read/write and eeadr holds the address of the eeprom location being accessed. the pic16f87/88 devices have 256 bytes of data eeprom with an address range from 00h to 0ffh. when writing to unimplemented locations, the charge pump will be turned off. when interfacing the program memory block, the eedata and eedath registers form a two-byte word that holds the 14-bit data for read/write and the eeadr and eeadrh registers form a two-byte word that holds the 13-bit address of the eeprom location being accessed. the pic16f87/88 devices have 4k words of program flash with an address range from 0000h to 0fffh. addresses above the range of the respective device will wraparound to the beginning of program memory. the eeprom data memory allows single byte read and write. the flash program memory allows single- word reads and four-word block writes. program memory writes must first start with a 32-word block erase, then write in 4-word blocks. a byte write in data eeprom memory automatically erases the location and writes the new data (erase before write). the write time is controlled by an on-chip timer. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device for byte or word operations. when the device is code-protected, the cpu may continue to read and write the data eeprom memory. depending on the settings of the write-protect bits, the device may or may not be able to write certain blocks of the program memory; however, reads of the program memory are allowed. when code-protected, the device programmer can no longer access data or program memory; this does not inhibit internal reads or writes. 3.1 eeadr and eeadrh the eeadrh:eeadr register pair can address up to a maximum of 256 bytes of data eeprom, or up to a maximum of 8k words of program eeprom. when selecting a data address value, only the lsb of the address is written to the eeadr register. when select- ing a program address value, the msb of the address is written to the eeadrh register and the lsb is written to the eeadr register. if the device contains less memory than the full address reach of the address register pair, the most significant bits of the registers are not implemented. for example, if the device has 128 bytes of data eeprom, the most significant bit of eeadr is not implemented on access to data eeprom. 3.2 eecon1 and eecon2 registers eecon1 is the control register for memory accesses. control bit eepgd determines if the access will be a program or data memory access. when clear, as it is when reset, any subsequent operations will operate on the data memory. when set, any subsequent operations will operate on the program memory. control bits, rd and wr, initiate read and write, respectively. these bits cannot be cleared, only set in software. they are cleared in hardware at completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental, premature termination of a write operation. the wren bit, when set, will allow a write or erase operation. on power-up, the wren bit is clear. the wrerr bit is set when a write (or erase) operation is interrupted by a mclr , or a wdt time-out reset dur- ing normal operation. in these situations, following reset, the user can check the wrerr bit and rewrite the location. the data and address will be unchanged in the eedata and eeadr registers. interrupt flag bit, eeif in the pir2 register, is set when the write is complete. it must be cleared in software. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the eeprom write sequence.
pic16f87/88 ds30487c-page 28 ? 2005 microchip technology inc. register 3-1: eecon1: eeprom access control register 1 (address 18ch) r/w-x u-0 u-0 r/w-x r/w-x r/w-0 r/s-0 r/s-0 eepgd ? ? free wrerr wren wr rd bit 7 bit 0 bit 7 eepgd : program/data eeprom select bit 1 = accesses program memory 0 = accesses data memory bit 6-5 unimplemented: read as ? 0 ? bit 4 free: eeprom forced row erase bit 1 = erase the program memory row addressed by eeadrh:eeadr on the next wr command 0 = perform write only bit 3 wrerr: eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr or any wdt reset during normal operation) 0 = the write operation completed bit 2 wren: eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the eeprom bit 1 wr: write control bit 1 = initiates a write cycle. the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software. 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read, rd is cleared in hardware. the rd bit can only be set (not cleared) in software. 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? s = set only -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 29 pic16f87/88 3.3 reading data eeprom memory to read a data memory location, the user must write the address to the eeadr register, clear the eepgd con- trol bit (eecon1<7>) and then set control bit rd (eecon1<0>). the data is available in the very next cycle in the eedata register; therefore, it can be read in the next instruction (see example 3-1). eedata will hold this value until another read or until it is written to by the user (during a write operation). the steps to reading the eeprom data memory are: 1. write the address to eeadr. make sure that the address is not larger than the memory size of the device. 2. clear the eepgd bit to point to eeprom data memory. 3. set the rd bit to start the read operation. 4. read the data from the eedata register. example 3-1: data eeprom read 3.4 writing to data eeprom memory to write an eeprom data location, the user must first write the address to the eeadr register and the data to the eedata register. then, the user must follow a specific write sequence to initiate the write for each byte. the write will not initiate if the write sequence is not exactly followed (write 55h to eecon2, write aah to eecon2, then set wr bit) for each byte. we strongly recommend that interrupts be disabled during this code segment (see example 3-2). additionally, the wren bit in eecon1 must be set to enable write. this mechanism prevents accidental writes to data eeprom due to errant (unexpected) code execution (i.e., lost programs). the user should keep the wren bit clear at all times except when updating eeprom. the wren bit is not cleared by hardware after a write sequence has been initiated, clearing the wren bit will not affect this write cycle. the wr bit will be inhibited from being set unless the wren bit is set. at the completion of the write cycle, the wr bit is cleared in hardware and the ee write complete interrupt flag bit (eeif) is set. the user can either enable this interrupt or poll this bit. eeif must be cleared by software. the steps to write to eeprom data memory are: 1. if step 10 is not implemented, check the wr bit to see if a write is in progress. 2. write the address to eeadr. make sure that the address is not larger than the memory size of the device. 3. write the 8-bit data value to be programmed in the eedata register. 4. clear the eepgd bit to point to eeprom data memory. 5. set the wren bit to enable program operations. 6. disable interrupts (if enabled). 7. execute the special five instruction sequence: write 55h to eecon2 in two steps (first to w, then to eecon2). write aah to eecon2 in two steps (first to w, then to eecon2). set the wr bit. 8. enable interrupts (if using interrupts). 9. clear the wren bit to disable program operations. 10. at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set (eeif must be cleared by firmware). if step 1 is not implemented, then firmware should check for eeif to be set, or wr to clear, to indicate the end of the program cycle. example 3-2: data eeprom write banksel eeadr ; select bank of eeadr movf addr, w ; movwf eeadr ; data memory address ; to read banksel eecon1 ; select bank of eecon1 bcf eecon1, eepgd; point to data memory bsf eecon1, rd ; ee read banksel eedata ; select bank of eedata movf eedata, w ; w = eedata banksel eecon1 ; select bank of ; eecon1 btfsc eecon1, wr ; wait for write goto $-1 ; to complete banksel eeadr ; select bank of ; eeadr movf addr, w ; movwf eeadr ; data memory ; address to write movf value, w ; movwf eedata ; data memory value ; to write banksel eecon1 ; select bank of ; eecon1 bcf eecon1, eepgd ; point to data ; memory bsf eecon1, wren ; enable writes bcf intcon, gie ; disable ints. movlw 55h ; movwf eecon2 ; write 55h movlw aah ; movwf eecon2 ; write aah bsf eecon1, wr ; set wr bit to ; begin write bsf intcon, gie ; enable ints. bcf eecon1, wren ; disable writes required sequence
pic16f87/88 ds30487c-page 30 ? 2005 microchip technology inc. 3.5 reading flash program memory to read a program memory location, the user must write two bytes of the address to the eeadr and eeadrh registers, set the eepgd control bit (eecon1<7>) and then set control bit rd (eecon1<0>). once the read control bit is set, the program memory flash controller will use the second instruction cycle to read the data. this causes the second instruction immediately following the ? bsf eecon1,rd ? instruction to be ignored. the data is available in the very next cycle in the eedata and eedath registers; therefore, it can be read as two bytes in the following instructions. eedata and eedath registers will hold this value until another read or until it is written to by the user (during a write operation). example 3-3: flash program read 3.6 erasing flash program memory the minimum erase block is 32 words. only through the use of an external programmer, or through icsp control, can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 32 words of program memory is erased. the most significant 11 bits of the eeadrh:eeadr point to the block being erased. eeadr< 4:0> are ignored. the eecon1 register commands the erase operation. the eepgd bit must be set to point to the flash program memory. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. after the ? bsf eecon1,wr ? instruction, the processor requires two cycles to setup the erase operation. the user must place two nop instructions after the wr bit is set. the processor will halt internal operations for the typical 2 ms, only during the cycle in which the erase takes place. this is not sleep mode, as the clocks and peripherals will continue to run. after the erase cycle, the processor will resume operation with the third instruction after the eecon1 write instruction. 3.6.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load eeadrh:eeadr with address of row being erased. 2. set eepgd bit to point to program memory, set wren bit to enable writes and set free bit to enable the erase. 3. disable interrupts. 4. write 55h to eecon2. 5. write aah to eecon2. 6. set the wr bit. this will begin the row erase cycle. 7. the cpu will stall for duration of the erase. banksel eeadrh ; select bank of eeadrh movf addrh, w ; movwf eeadrh ; ms byte of program ; address to read movf addrl, w ; movwf eeadr ; ls byte of program ; address to read banksel eecon1 ; select bank of eecon1 bsf eecon1, eepgd ; point to program ; memory bsf eecon1, rd ; ee read ; nop ; any instructions ; here are ignored as nop ; program memory is ; read in second cycle ; after bsf eecon1,rd banksel eedata ; select bank of eedata movf eedata, w ; datal = eedata movwf datal ; movf eedath, w ; datah = eedath movwf datah ;
? 2005 microchip technology inc. ds30487c-page 31 pic16f87/88 example 3-4: erasing a flash program memory row banksel eeadrh ; select bank of eeadrh movf addrh, w ; movwf eeadrh ; ms byte of program address to erase movf addrl, w ; movwf eeadr ; ls byte of program address to erase erase_row banksel eecon1 ; select bank of eecon1 bsf eecon1, eepgd ; point to program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation ; bcf intcon, gie ; disable interrupts (if using) movlw 55h ; movwf eecon2 ; write 55h movlw aah ; movwf eecon2 ; write aah bsf eecon1, wr ; start erase (cpu stall) nop ; any instructions here are ignored as processor ; halts to begin erase sequence nop ; processor will stop here and wait for erase complete ; after erase processor continues with 3rd instruction bcf eecon1, free ; disable row erase operation bcf eecon1, wren ; disable writes bsf intcon, gie ; enable interrupts (if using)
pic16f87/88 ds30487c-page 32 ? 2005 microchip technology inc. 3.7 writing to flash program memory flash program memory may only be written to if the destination address is in a segment of memory that is not write-protected, as defined in bits wrt1:wrt0 of the device configuration word (register 15-1). flash program memory must be written in four-word blocks. a block consists of four words with sequential addresses, with a lower boundary defined by an address, where eeadr<1:0> = 00 . at the same time, all block writes to program memory are done as write- only operations. the program memory must first be erased. the write operation is edge-aligned and cannot occur across boundaries. to write to the program memory, the data must first be loaded into the buffer registers. there are four 14-bit buffer registers and they are addressed by the low 2 bits of eeadr. the following sequence of events illustrate how to perform a write to program memory:  set the eepgd and wren bits in the eecon1 register  clear the free bit in eecon1  write address to eeadrh:eeadr  write data to eedath:eedata  write 55 to eecon2  write aa to eecon2  set wr bit in eecon1 the user must follow the same specific sequence to initiate the write for each word in the program block by writing each program word in sequence ( 00 , 01 , 10 , 11 ). there are 4 buffer register words and all four locations must be written to with correct data. after the ? bsf eecon1, wr ? instruction, if eeadr xxxxxx11 , then a short write will occur. this short write only transfers the data to the buffer register. the wr bit will be cleared in hardware after 1cycle. after the ? bsf eecon1, wr ? instruction, if eeadr = xxxxxx11 , then a long write will occur. this will simultaneously transfer the data from eedath:eedata to the buffer registers and begin the write of all four words. the processor will execute the next instruction and then ignore the subsequent instruction. the user should place nop instructions into the second words. the processor will then halt internal operations for typically 2 msec in which the write takes place. this is not sleep mode, as the clocks and peripherals will continue to run. after the write cycle, the processor will resume operation with the 3rd instruction after the eecon1 write instruction. after each long write, the 4 buffer registers will be reset to 3fff. figure 3-1: block writes to flash program memory 14 14 14 14 program memory buffer register eeadr<1:0> = 00 buffer register eeadr<1:0> = 01 buffer register eeadr<1:0> = 10 buffer register eeadr<1:0> = 11 eedata eedath 75 07 0 6 8 first word of block to be written to flash automatically after this word is written transferred all buffers are
? 2005 microchip technology inc. ds30487c-page 33 pic16f87/88 an example of the complete four-word write sequence is shown in example 3-5. the initial address is loaded into the eeadrh:eeadr register pair; the four words of data are loaded using indirect addressing, assuming that a row erase sequence has already been performed. example 3-5: writing to flash program memory ; this write routine assumes the following: ; 1. the 32 words in the erase block have already been erased. ; 2. a valid starting address (the least significant bits = '00') is loaded into eeadrh:eeadr ; 3. this example is starting at 0x100, this is an application dependent setting. ; 4. the 8 bytes (4 words) of data are loaded, starting at an address in ram called array. ; 5. this is an example only, location of data to program is application dependent. ; 6. word_block is located in data memory. banksel eecon1 ;prepare for write procedure bsf eecon1, eepgd ;point to program memory bsf eecon1, wren ;allow write cycles bcf eecon1, free ;perform write only banksel word_block movlw .4 movwf word_block ;prepare for 4 words to be written banksel eeadrh ;start writing at 0x100 movlw 0x01 movwf eeadrh ;load high address movlw 0x00 movwf eeadr ;load low address banksel array movlw array ;initialize fsr to start of data movwf fsr loop banksel eedata movf indf, w ;indirectly load eedata movwf eedata incf fsr, f ;increment data pointer movf indf, w ;indirectly load eedath movwf eedath incf fsr, f ;increment data pointer banksel eecon1 movlw 0x55 ;required sequence movwf eecon2 movlw 0xaa movwf eecon2 bsf eecon1, wr ;set wr bit to begin write nop ;instructions here are ignored as processor nop banksel eeadr incf eeadr, f ;load next word address banksel word_block decfsz word_block, f ;have 4 words been written? goto loop ;no, continue with writing banksel eecon1 bcf eecon1, wren ;yes, 4 words complete, disable writes bsf intcon,gie ;enable interrupts required sequence
pic16f87/88 ds30487c-page 34 ? 2005 microchip technology inc. 3.8 protection against spurious write there are conditions when the device should not write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built-in. on power-up, wren is cleared. also, the power-up timer (72 ms duration) prevents an eeprom write. the write initiate sequence and the wren bit together help prevent an accidental write during brown-out, power glitch or software malfunction. 3.9 operation during code-protect when the data eeprom is code-protected, the micro- controller can read and write to the eeprom normally. however, all external access to the eeprom is disabled. external write access to the program memory is also disabled. when program memory is code-protected, the micro- controller can read and write to program memory normally, as well as execute instructions. writes by the device may be selectively inhibited to regions of the memory depending on the setting of bits wrt1:wrt0 of the configuration word (see section 15.1 ?config- uration bits? for additional information). external access to the memory is also disabled. table 3-1: registers/bits associated with data eeprom and flash program memories address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on power-on reset value on all other resets 10ch eedata eeprom/flash data register low byte xxxx xxxx uuuu uuuu 10dh eeadr eeprom/flash address register low byte xxxx xxxx uuuu uuuu 10eh eedath ? ? eeprom/flash data register high byte --xx xxxx --uu uuuu 10fh eeadrh ? ? ? ? eeprom/flash address register high byte ---- xxxx ---- uuuu 18ch eecon1 eepgd ? ? free wrerr wren wr rd x--x x000 x--x q000 18dh eecon2 eeprom control register 2 (not a physical register) ---- ---- ---- ---- 0dh pir2 osfif cmif ?eeif ? ? ? ? 00-0 ---- 00-0 ---- 8dh pie2 osfie cmie ?eeie ? ? ? ? 00-0 ---- 00-0 ---- legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?, q = value depends upon condition. shaded cells are not used by data eeprom or flash program memory.
? 2005 microchip technology inc. ds30487c-page 35 pic16f87/88 4.0 oscillator configurations 4.1 oscillator types the pic16f87/88 can be operated in eight different oscillator modes. the user can program three configu- ration bits (fosc2:fosc0) to select one of these eight modes (modes 5-8 are new pic16 oscillator configurations): 1. lp low-power crystal 2. xt crystal/resonator 3. hs high-speed crystal/resonator 4. rc external resistor/capacitor with f osc /4 output on ra6 5. rcio external resistor/capacitor with i/o on ra6 6. intio1 internal oscillator with f osc /4 output on ra6 and i/o on ra7 7. intio2 internal oscillator with i/o on ra6 and ra7 8. ecio external clock with i/o on ra6 4.2 crystal oscillator/ceramic resonators in xt, lp or hs modes, a crystal or ceramic resonator is connected to the osc1/clki and osc2/clko pins to establish oscillation (see figure 4-1 and figure 4-2). the pic16f87/88 oscillator design requires the use of a parallel cut crystal. use of a series cut crystal may give a frequency out of the crystal manufacturer?s specifications. figure 4-1: crystal operation (hs, xt, or lp oscillator configuration) table 4-1: capacitor selection for crystal oscillator (for design guidance only) note1: see table 4-1 for typical values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the crystal chosen (typically between 2 m ? to 10 m ?) . c1 (1) c2 (1) xtal osc2 r s (2) osc1 r f (3) sleep to internal logic pic16f87/88 osc type crystal freq typical capacitor values tested: c1 c2 lp 32 khz 33 pf 33 pf xt 200 khz 56 pf 56 pf 1 mhz 15 pf 15 pf 4 mhz 15 pf 15 pf hs 4 mhz 15 pf 15 pf 8 mhz 15 pf 15 pf 20 mhz 15 pf 15 pf capacitor values are for design guidance only. these capacitors were tested with the crystals listed below for basic start-up and operation. these values were not optimized. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following this table for additional information. note 1: higher capacitance increases the stability of oscillator but also increases the start-up time. 2: since each crystal has its own character- istics, the user should consult the crystal manufacturer for appropriate values of external components. 3: rs may be required in hs mode, as well as xt mode, to avoid overdriving crystals with low drive level specification. 4: always verify oscillator performance over the v dd and temperature range that is expected for the application.
pic16f87/88 ds30487c-page 36 ? 2005 microchip technology inc. figure 4-2: ceramic resonator operation (hs or xt osc configuration) table 4-2: ceramic resonators (for design guidance only) 4.3 external clock input the ecio oscillator mode requires an external clock source to be connected to the osc1 pin. there is no oscillator start-up time required after a power-on reset, or after an exit from sleep mode. in the ecio oscillator mode, the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 4-3 shows the pin connections for the ecio oscillator mode. figure 4-3: external clock input operation (ecio configuration) typical capacitor values used: mode freq osc1 osc2 xt 455 khz 2.0 mhz 4.0 mhz 56 pf 47 pf 33 pf 56 pf 47 pf 33 pf hs 8.0 mhz 16.0 mhz 27 pf 22 pf 27 pf 22 pf capacitor values are for design guidance only. these capacitors were tested with the resonators listed below for basic start-up and operation. these values were not optimized. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following this table for additional information. note: when using resonators with frequencies above 3.5 mhz, the use of hs mode, rather than xt mode, is recommended. hs mode may be used at any v dd for which the controller is rated. if hs is selected, it is possible that the gain of the oscillator will overdrive the resonator. therefore, a series resistor should be placed between the osc2 pin and the resonator. as a good starting point, the recommended value of r s is 330 ?. note 1: see table 4-2 for typical values of c1 and c2. 2: a series resistor (r s ) may be required. 3: r f varies with the resonator chosen (typically between 2 m ? to 10 m ?) . c1 (1) c2 (1) res osc2 r s (2) osc1 r f (3) sleep to internal logic pic16f87/88 osc1/clki i/o (osc2) ra6 clock from ext. system pic16f87/88
? 2005 microchip technology inc. ds30487c-page 37 pic16f87/88 4.4 rc oscillator for timing insensitive applications, the ?rc? and ?rcio? device options offer additional cost savings. the rc oscillator frequency is a function of the supply voltage, the resistor (r ext ) and capacitor (c ext ) val- ues and the operating temperature. in addition to this, the oscillator frequency will vary from unit to unit due to normal manufacturing variation. furthermore, the dif- ference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low c ext values. the user also needs to take into account variation due to tolerance of external r and c components used. figure 4-4 shows how the r/c combination is connected. in the rc oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 4-4: rc oscillator mode the rcio oscillator mode (figure 4-5) functions like the rc mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 4-5: rcio oscillator mode 4.5 internal oscillator block the pic16f87/88 devices include an internal oscillator block which generates two different clock signals; either can be used as the system?s clock source. this can eliminate the need for external oscillator circuits on the osc1 and/or osc2 pins. the main output (intosc) is an 8 mhz clock source which can be used to directly drive the system clock. it also drives the intosc postscaler which can provide a range of six clock frequencies from 125 khz to 4 mhz. the other clock source is the internal rc oscillator (intrc) which provides a 31.25 khz (32 s nominal period) output. the intrc oscillator is enabled by selecting the intrc as the system clock source or when any of the following are enabled:  power-up timer  watchdog timer  two-speed start-up  fail-safe clock monitor these features are discussed in greater detail in section 15.0 ?special features of the cpu? . the clock source frequency (intosc direct, intrc direct or intosc postscaler) is selected by configuring the ircf bits of the osccon register (page 40). osc2/clko c ext r ext pic16f87/88 osc1 f osc /4 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20 pf c ext r ext pic16f87/88 osc1 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20 pf i/o (osc2) ra6 note: throughout this data sheet, when referring specifically to a generic clock source, the term ?intrc? may also be used to refer to the clock modes using the internal oscillator block. this is regardless of whether the actual frequency used is intosc (8 mhz), the intosc postscaler or intrc (31.25 khz).
pic16f87/88 ds30487c-page 38 ? 2005 microchip technology inc. 4.5.1 intrc modes using the internal oscillator as the clock source can eliminate the need for up to two external oscillator pins, after which it can be used for digital i/o. two distinct configurations are available:  in intio1 mode, the osc2 pin outputs f osc /4, while osc1 functions as ra7 for digital input and output.  in intio2 mode, osc1 functions as ra7 and osc2 functions as ra6, both for digital input and output. 4.5.2 osctune register the internal oscillator?s output has been calibrated at the factory but can be adjusted in the application. this is done by writing to the osctune register (register 4-1). the tuning sensitivity is constant throughout the tuning range. the osctune register has a tuning range of 12.5%. when the osctune register is modified, the intosc and intrc frequencies will begin shifting to the new fre- quency. the intrc clock will reach the new frequency within 8 clock cycles (approximately 8 * 32 s = 256 s); the intosc clock will stabilize within 1 ms. code execu- tion continues during this shift. there is no indication that the shift has occurred. operation of features that depend on the 31.25 khz intrc clock source frequency, such as the wdt, fail-safe clock monitor and peripherals, will also be affected by the change in frequency. register 4-1: osctune: oscillator tuning register (address 90h) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frequency tuning bits 011111 = maximum frequency 011110 =    000001 = 000000 = center frequency. oscillator module is running at the calibrated frequency. 111111 =    100000 = minimum frequency legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 39 pic16f87/88 4.6 clock sources and oscillator switching the pic16f87/88 devices include a feature that allows the system clock source to be switched from the main oscillator to an alternate low-frequency clock source. pic16f87/88 devices offer three alternate clock sources. when enabled, these give additional options for switching to the various power-managed operating modes. essentially, there are three clock sources for these devices:  primary oscillators  secondary oscillators  internal oscillator block (intrc) the primary oscillators include the external crystal and resonator modes, the external rc modes, the external clock mode and the internal oscillator block. the particular mode is defined on por by the contents of configuration word 1. the details of these modes are covered earlier in this chapter. the secondary oscillators are those external sources not connected to the osc1 or osc2 pins. these sources may continue to operate even after the controller is placed in a power-managed mode. pic16f87/88 devices offer the timer1 oscillator as a secondary oscillator. this oscillator continues to run when a sleep instruction is executed and is often the time base for functions such as a real-time clock. most often, a 32.768 khz watch crystal is connected between the rb6/t1oso and rb7/t1osi pins. like the lp mode oscillator circuit, loading capacitors are also connected from each pin to ground. the timer1 oscillator is discussed in greater detail in section 7.6 ?timer1 oscillator? . in addition to being a primary clock source, the internal oscillator block is available as a power-managed mode clock source. the 31.25 khz intrc source is also used as the clock source for several special features, such as the wdt, fail-safe clock monitor, power-up timer and two-speed start-up. the clock sources for the pic16f87/88 devices are shown in figure 4-6. see section 7.0 ?timer1 mod- ule? for further details of the timer1 oscillator. see section 15.1 ?configuration bits? for configuration register details. 4.6.1 osccon register the osccon register (register 4-2) controls several aspects of the system clock?s operation, both in full power operation and in power-managed modes. the system clock select bits, scs1:scs0, select the clock source that is used when the device is operating in power-managed modes. when the bits are cleared (scs<1:0> = 00 ), the system clock source comes from the main oscillator that is selected by the fosc2:fosc0 configuration bits in configuration word 1 register. when the bits are set in any other manner, the system clock source is provided by the timer1 oscillator (scs1:scs0 = 01 ) or from the internal oscillator block (scs1:scs0 = 10 ). after a reset, scs<1:0> are always set to ? 00 ?. the internal oscillator select bits, ircf2:ircf0, select the frequency output of the internal oscillator block that is used to drive the system clock. the choices are the intrc source (31.25 khz), the intosc source (8 mhz) or one of the six frequencies derived from the intosc postscaler (125 khz to 4 mhz). changing the configuration of these bits has an immediate change on the multiplexor?s frequency output. the osts and iofs bits indicate the status of the primary oscillator and intosc source; these bits are set when their respective oscillators are stable. in particular, osts indicates that the oscillator start-up timer has timed out. 4.6.2 clock switching clock switching will occur for the following reasons:  the fcmen (config2<0>) bit is set, the device is running from the primary oscillator and the primary oscillator fails. the clock source will be the internal rc oscillator.  the fcmen bit is set, the device is running from the t1osc and t1osc fails. the clock source will be the internal rc oscillator.  following a wake-up due to a reset or a por, when the device is configured for two-speed start-up mode, switching will occur between the intrc and the system clock defined by the fosc<2:0> bits.  a wake-up from sleep occurs due to an interrupt or wdt wake-up and two-speed start-up is enabled. if the primary clock is xt, hs or lp, the clock will switch between the intrc and the primary system clock after 1024 clocks (ost) and 8 clocks of the primary oscillator. this is conditional upon the scs bits being set equal to ? 00 ?.  scs bits are modified from their original value.  ircf bits are modified from their original value. note: the instruction to immediately follow the modification of scs<1:0> will have an instruction time (t cy ) based on the previ- ous clock source. this should be taken into consideration when developing time dependant code. note: because the scs bits are cleared on any reset, no clock switching will occur on a reset unless the two-speed start-up is enabled and the primary clock is xt, hs or lp. the device will wait for the primary clock to become stable before execution begins (two-speed start-up disabled).
pic16f87/88 ds30487c-page 40 ? 2005 microchip technology inc. 4.6.3 clock transition and wdt when clock switching is performed, the watchdog timer is disabled because the watchdog ripple counter is used as the oscillator start-up timer. once the clock transition is complete (i.e., new oscilla- tor selection switch has occurred), the watchdog counter is re-enabled with the counter reset. this allows the user to synchronize the watchdog timer to the start of execution at the new clock frequency. register 4-2: osccon: oscillator control regi ster (address 8fh) note: the ost is only used when switching to xt, hs and lp oscillator modes. u-0 r/w-0 r/w-0 r/w-0 r-0 r/w-0 r/w-0 r/w-0 ? ircf2 ircf1 ircf0 osts (1) iofs scs1 scs0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-4 ircf<2:0>: internal rc oscillator frequency select bits 000 = 31.25 khz 001 = 125 khz 010 = 250 khz 011 = 500 khz 100 = 1 mhz 101 = 2 mhz 110 = 4 mhz 111 = 8 mhz bit 3 osts: oscillator start-up time-out status bit (1) 1 = device is running from the primary system clock 0 = device is running from t1osc or intrc as a secondary system clock note 1: bit resets to ? 0 ? with two-speed start-up mode and lp, xt or hs selected as the oscillator mode. bit 2 iofs: intosc frequency stable bit 1 = frequency is stable 0 = frequency is not stable bit 1-0 scs<1:0>: oscillator mode select bits 00 = oscillator mode defined by fosc<2:0> 01 = t1osc is used for system clock 10 = internal rc is used for system clock 11 = reserved legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 41 pic16f87/88 figure 4-6: pic16f87 /88 clock diagram 4.6.4 modifying the ircf bits the ircf bits can be modified at any time regardless of which clock source is currently being used as the system clock. the internal oscillator allows users to change the frequency during run time. this is achieved by modifying the ircf bits in the osccon register. the sequence of events that occur after the ircf bits are modified is dependent upon the initial value of the ircf bits before they are modified. if the intrc (31.25 khz, ircf<2:0> = 000 ) is running and the ircf bits are modified to any other value than ? 000 ?, a 4 ms (approx.) clock switch delay is turned on. code execu- tion continues at a higher than expected frequency while the new frequency stabilizes. time sensitive code should wait for the iofs bit in the osccon register to become set before continuing. this bit can be moni- tored to ensure that the frequency is stable before using the system clock in time critical applications. if the ircf bits are modified while the internal oscillator is running at any other frequency than intrc (31.25 khz, ircf<2:0> 000 ), there is no need for a 4 ms (approx.) clock switch delay. the new intosc frequency will be stable immediately after the eight fall- ing edges. the iofs bit will remain set after clock switching occurs. 4.6.5 clock transition sequence following are three different sequences for switching the internal rc oscillator frequency.  clock before switch: 31.25 khz (ircf<2:0> = 000 ) 1. ircf bits are modified to an intosc/intosc postscaler frequency. 2. the clock switching circuitry waits for a falling edge of the current clock, at which point clko is held low. 3. the clock switching circuitry then waits for eight falling edges of requested clock, after which it switches clko to this new clock source. 4. the iofs bit is clear to indicate that the clock is unstable and a 4 ms (approx.) delay is started. time dependent code should wait for iofs to become set. 5. switchover is complete.  clock before switch: one of intosc/intosc postscaler (ircf<2:0> 000 ) 1. ircf bits are modified to intrc (ircf<2:0> = 000 ). 2. the clock switching circuitry waits for a falling edge of the current clock, at which point clko is held low. 3. the clock switching circuitry then waits for eight falling edges of requested clock, after which it switches clko to this new clock source. 4. oscillator switchover is complete. secondary oscillator t1oscen enable oscillator t1oso t1osi osc1 osc2 sleep primary oscillator lp, xt, hs, rc, ec t1osc cpu peripherals postscaler mux mux 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz osccon<6:4> 111 110 101 100 011 010 001 000 31.25 khz 31.25 khz source internal oscillator block wdt, fscm 31.25 khz 8 mhz internal oscillator (intrc) (intosc) configuration word 1 (fosc2:fosc0) scs<1:0> (t1osc) to timer1 note: caution must be taken when modifying the ircf bits using bcf or bsf instructions. it is possible to modify the ircf bits to a frequency that may be out of the v dd spec- ification range; for example, v dd = 2.0v and ircf = 111 (8 mhz).
pic16f87/88 ds30487c-page 42 ? 2005 microchip technology inc.  clock before switch: one of intosc/intosc postscaler (ircf<2:0> 000 ) 1. ircf bits are modified to a different intosc/ intosc postscaler frequency. 2. the clock switching circuitry waits for a falling edge of the current clock, at which point clko is held low. 3. the clock switching circuitry then waits for eight falling edges of requested clock, after which it switches clko to this new clock source. 4. the iofs bit is set. 5. oscillator switchover is complete. 4.6.6 oscillator delay upon power-up, wake-up and clock switching table 4-3 shows the different delays invoked for various clock switching sequences. it also shows the delays invoked for por and wake-up. table 4-3: oscillator delay examples clock switch frequency oscillator delay comments from to sleep/por intrc t1osc 31.25 khz 32.768 khz cpu start-up (1) following a wake-up from sleep mode or por, cpu start-up is invoked to allow the cpu to become ready for code execution. intosc/ intosc postscaler 125 khz-8 mhz 4 ms (approx.) and cpu start-up (1) intrc/sleep ec, rc dc ? 20 mhz intrc (31.25 khz) ec, rc dc ? 20 mhz sleep lp, xt, hs 32.768 khz-20 mhz 1024 clock cycles (ost) following a change from intrc, an ost of 1024 cycles must occur. intrc (31.25 khz) intosc/ intosc postscaler 125 khz-8 mhz 4 ms (approx.) refer to section 4.6.4 ?modifying the ircf bits? for further details. note 1: the 5-10 s start-up delay is based on a 1 mhz system clock.
? 2005 microchip technology inc. ds30487c-page 43 pic16f87/88 4.7 power-managed modes 4.7.1 rc_run mode when scs bits are configured to run from the intrc, a clock transition is generated if the system clock is not already using the intrc. the event will clear the osts bit, switch the system clock from the primary system clock (if scs<1:0> = 00 ) determined by the value contained in the configuration bits, or from the t1osc (if scs<1:0> = 01 ) to the intrc clock option and shut down the primary system clock to conserve power. clock switching will not occur if the primary system clock is already configured as intrc. if the system clock does not come from the intrc (31.25 khz) when the scs bits are changed and the ircf bits in the osccon register are configured for a frequency other than intrc, the frequency may not be stable immediately. the iofs bit (osccon<2>) will be set when the intosc or postscaler frequency is stable, after 4 ms (approx.). after a clock switch has been executed, the osts bit is cleared, indicating a low-power mode and the device does not run from the primary system clock. the internal q clocks are held in the q1 state until eight falling edge clocks are counted on the intrc oscillator. after the eight clock periods have transpired, the clock input to the q clocks is released and operation resumes (see figure 4-7). figure 4-7: timing diagram for xt, hs, lp, ec and extrc to rc_run mode q4 q3 q2 osc1 scs<1:0> program pc + 1 pc note 1: t inp =32 s typical. 2: t osc = 50 ns minimum. 3: t scs =8 t inp . 4: t dly =1 t inp . q1 intosc q1 t scs (3) counter q1 t dly (4) t inp (1) system clock t osc (2) q3 q2 q4 q1 q2 pc + 3 q3 q4 q1 pc + 2
pic16f87/88 ds30487c-page 44 ? 2005 microchip technology inc. 4.7.2 sec_run mode the core and peripherals can be configured to be clocked by t1osc using a 32.768 khz crystal. the crystal must be connected to the t1oso and t1osi pins. this is the same configuration as the low-power timer circuit (see section 7.6 ?timer1 oscillator? ). when scs bits are configured to run from t1osc, a clock transition is generated. it will clear the osts bit, switch the system clock from either the primary system clock or intrc, depending on the value of scs<1:0> and fosc<2:0>, to the external low-power timer1 oscillator input (t1osc) and shut down the primary system clock to conserve power. after a clock switch has been executed, the internal q clocks are held in the q1 state until eight falling edge clocks are counted on the t1osc. after the eight clock periods have transpired, the clock input to the q clocks is released and operation resumes (see figure 4-8). in addition, t1run (in t1con) is set to indicate that t1osc is being used as the system clock. figure 4-8: timing diagram fo r switching to sec_run mode note 1: the t1oscen bit must be enabled and it is the user?s responsibility to ensure t1osc is stable before clock switching to the t1osc input clock can occur. 2: when t1oscen = 0 , the following possible effects result. original scs<1:0> modified scs<1:0> final scs<1:0> 00 01 00 ? no change 00 11 10 ? intrc 10 11 10 ? no change 10 01 00 ? oscillator defined by fosc<2:0> a clock switching event will occur if the final state of the scs bits is different from the original. q4 q3 q2 osc1 scs<1:0> program pc +1 pc note 1: t t 1 p = 30.52 s. 2: t osc = 50 ns minimum. 3: t scs = 8 t t 1 p 4: t dly = 1 t t 1 p . q1 t1osi q1 t scs (3) counter q1 t dly (4) t t 1 p (1) system clock t osc (2) q3 q2 q4 q1 q2 pc + 3 q3 q4 q1 pc + 2
? 2005 microchip technology inc. ds30487c-page 45 pic16f87/88 4.7.3 sec_run/rc_run to primary clock source when switching from a sec_run or rc_run mode back to the primary system clock, following a change of scs<1:0> to ? 00 ?, the sequence of events that takes place will depend upon the value of the fosc bits in the configuration register. if the primary clock source is configured as a crystal (hs, xt or lp), then the tran- sition will take place after 1024 clock cycles. this is necessary because the crystal oscillator has been powered down until the time of the transition. in order to provide the system with a reliable clock when the changeover has occurred, the clock will not be released to the changeover circuit until the 1024 count has expired. during the oscillator start-up time, the system clock comes from the current system clock. instruction execution and/or peripheral operation continues using the currently selected oscillator as the cpu clock source, until the necessary clock count has expired, to ensure that the primary system clock is stable. to know when the ost has expired, the osts bit should be monitored. osts = 1 indicates that the oscillator start-up timer has timed out and the system clock comes from the primary clock source. following the oscillator start-up time, the internal q clocks are held in the q1 state until eight falling edge clocks are counted from the primary system clock. the clock input to the q clocks is then released and opera- tion resumes with the primary system clock determined by the fosc bits (see figure 4-10). when in sec_run mode, the act of clearing the t1oscen bit in the t1con register will cause scs<0> to be cleared, which causes the scs<1:0> bits to revert to ? 00 ? or ? 10 ? depending on what scs<1> is. although the t1oscen bit was cleared, t1osc will be enabled and instruction execution will continue until the ost time-out for the main system clock is com- plete. at that time, the system clock will switch from the t1osc to the primary clock or the intrc. following this, the t1 oscillator will be shut down. 4.7.3.1 returning to primary clock source sequence changing back to the primary oscillator from sec_run or rc_run can be accomplished by either changing scs<1:0> to ? 00 ?, or clearing the t1oscen bit in the t1con register (if t1osc was the secondary clock). the sequence of events that follows is the same for both modes: 1. if the primary system clock is configured as ec, rc or intrc, then the ost time-out is skipped. skip to step 3. 2. if the primary system clock is configured as an external oscillator (hs, xt, lp), then the ost will be active, waiting for 1024 clocks of the primary system clock. 3. on the following q1, the device holds the system clock in q1. 4. the device stays in q1 while eight falling edges of the primary system clock are counted. 5. once the eight counts transpire, the device begins to run from the primary oscillator. 6. if the secondary clock was intrc and the primary is not intrc, the intrc will be shut down to save current providing that the intrc is not being used for any other function, such as wdt or fail-safe clock monitoring. 7. if the secondary clock was t1osc, the t1osc will continue to run if t1oscen is still set; otherwise, the t1 oscillator will be shut down. note: if the primary system clock is either rc or ec, an internal delay timer (5-10 s) will suspend operation after exiting secondary clock mode to allow the cpu to become ready for code execution.
pic16f87/88 ds30487c-page 46 ? 2005 microchip technology inc. figure 4-9: timing for transition between sec_run/rc_run and primary clock q4 q1 q3 q4 osc1 program pc pc + 1 secondary primary clock t ost q1 pc + 3 t dly (5) t t 1 p (1) or t inp (2) t scs (4) q2 osc2 q3 q4 q1 osts system clock pc + 2 counter q2 q2 q3 q4 scs<1:0> note 1: t t 1 p = 30.52 s. 2: t inp = 32 s typical. 3: t osc = 50 ns minimum. 4: t scs = 8 t inp or 8t t 1 p . 5: t dly = 1 t inp or 1t t 1 p . oscillator t osc (3)
? 2005 microchip technology inc. ds30487c-page 47 pic16f87/88 4.7.3.2 returning to primary oscillator with a reset a reset will clear scs<1:0> back to ? 00 ?. the sequence for starting the primary oscillator following a reset is the same for all forms of reset, including por. there is no transition sequence from the alternate system clock to the primary system clock on a reset condition. instead, the device will reset the state of the osccon register and default to the primary system clock. the sequence of events that takes place after this will depend upon the value of the fosc bits in the configuration register. if the external oscillator is configured as a crystal (hs, xt or lp), the cpu will be held in the q1 state until 1024 clock cycles have transpired on the primary clock. this is necessary because the crystal oscillator has been powered down until the time of the transition. during the oscillator start-up time, instruction execution and/or peripheral operation is suspended. if the primary system clock is either rc, ec or intrc, the cpu will begin operating on the first q1 cycle following the wake-up event. this means that there is no oscillator start-up time required because the primary clock is already stable; however, there is a delay between the wake-up event and the following q2. an internal delay timer of 5-10 s will suspend operation after the reset to allow the cpu to become ready for code execution. the cpu and peripheral clock will be held in the first q1. the sequence of events is as follows: 1. a device reset is asserted from one of many sources (wdt, bor, mclr , etc.). 2. the device resets and the cpu start-up timer is enabled if in sleep mode. the device is held in reset until the cpu start-up time-out is complete. 3. if the primary system clock is configured as an external oscillator (hs, xt, lp), then the ost will be active waiting for 1024 clocks of the primary system clock. while waiting for the ost, the device will be held in reset. the ost and cpu start-up timers run in parallel. 4. after both the cpu start-up and ost timers have timed out, the device will wait for one addi- tional clock cycle and instruction execution will begin. figure 4-10: primary system clock after reset (hs, xt, lp) note: if two-speed clock start-up mode is enabled, the intrc will act as the system clock until the ost timer has timed out. q4 q1 q3 q4 q1 q2 osc1 peripheral sleep program pc 0000h t1osi t ost q3 t t 1 p (1) q4 osc2 osts system clock 0001h q1 q2 q3 q4 q1 q2 clock counter 0004h 0005h 0003h q1 q2 q3 q4 reset t cpu (3) note 1: t t 1 p = 30.52 s. 2: t osc = 50 ns minimum. 3: t cpu = 5-10 s (1 mhz system clock). cpu start-up t osc (2)
pic16f87/88 ds30487c-page 48 ? 2005 microchip technology inc. figure 4-11: primary system clock after reset (ec, rc, intrc) q4 q1 q3 q4 q1 q2 osc1 program pc 0000h t1osi q3 t t 1 p (1) q4 osc2 osts system clock 0001h q1 q2 q3 q4 q1 q2 counter 0003h 0004h 0002h q1 q2 q3 q4 mclr t cpu (2) note 1: t t 1 p = 30.52 s. 2: t cpu = 5-10 s (1 mhz system clock). cpu start-up
? 2005 microchip technology inc. ds30487c-page 49 pic16f87/88 table 4-4: clock switching modes current system clock scs bits <1:0> modified to: delay osts bit iofs bit t1run bit new system clock comments lp, xt, hs, t1osc, ec, rc 10 (intrc) fosc<2:0> = lp, xt or hs 8 clocks of intrc 01 (1) 0 intrc or intosc or intosc postscaler the internal rc oscillator frequency is dependant upon the ircf bits. lp, xt, hs, intrc, ec, rc 01 (t1osc) fosc<2:0> = lp, xt or hs 8 clocks of t1osc 0 n/a 1 t1osc t1oscen bit must be enabled. intrc t1osc 00 fosc<2:0> = ec or fosc<2:0> = rc 8 clocks of ec or rc 1 n/a 0 ec or rc intrc t1osc 00 fosc<2:0> = lp, xt, hs 1024 clocks (ost) + 8 clocks of lp, xt, hs 1 n/a 0 lp, xt, hs during the 1024 clocks, program execution is clocked from the secondary oscillator until the primary oscillator becomes stable. lp, xt, hs 00 (due to reset) lp, xt, hs 1024 clocks (ost) 1 n/a 0 lp, xt, hs when a reset occurs, there is no clock transition sequence. instruction execution and/or peripheral operation is suspended unless two-speed start-up mode is enabled, after which the intrc will act as the system clock until the ost timer has expired. note 1: if the new clock source is the intosc or intosc post scaler, then the iofs bit will be set 4 ms (approx.) after the clock change.
pic16f87/88 ds30487c-page 50 ? 2005 microchip technology inc. 4.7.4 exiting sleep with an interrupt any interrupt, such as wdt or int0, will cause the part to leave the sleep mode. the scs bits are unaffected by a sleep command and are the same before and after entering and leaving sleep. the clock source used after an exit from sleep is determined by the scs bits. 4.7.4.1 sequence of events if scs<1:0> = 00 : 1. the device is held in sleep until the cpu start-up time-out is complete. 2. if the primary system clock is configured as an external oscillator (hs, xt, lp), then the ost will be active waiting for 1024 clocks of the primary system clock. while waiting for the ost, the device will be held in sleep unless two-speed start-up is enabled. the ost and cpu start-up timers run in parallel. refer to section 15.12.3 ?two-speed clock start-up mode? for details on two-speed start-up. 3. after both the cpu start-up and ost timers have timed out, the device will exit sleep and begin instruction execution with the primary clock defined by the fosc bits. if scs<1:0> = 01 or 10 : 1. the device is held in sleep until the cpu start-up time-out is complete. 2. after the cpu start-up timer has timed out, the device will exit sleep and begin instruction execution with the selected oscillator mode. note: if a user changes scs<1:0> just before entering sleep mode, the system clock used when exiting sleep mode could be different than the system clock used when entering sleep mode. as an example, if scs<1:0> = 01 and t1osc is the system clock and the following instructions are executed: bcf osccon, scs0 sleep then a clock change event is executed. if the primary oscillator is xt, lp or hs, the core will continue to run off t1osc and execute the sleep command. when sleep is exited, the part will resume operation with the primary oscillator after the ost has expired.
? 2005 microchip technology inc. ds30487c-page 51 pic16f87/88 5.0 i/o ports some pins for these i/o ports are multiplexed with an alternate function for the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. additional information on i/o ports may be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023). 5.1 porta and the trisa register porta is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisa. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register, reads the status of the pins, whereas writing to it, will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. pin ra4 is multiplexed with the timer0 module clock input. on pic16f88 devices, it is also multiplexed with an analog input to become the ra4/an4/t0cki/ c2out pin. the ra4/an4/t0cki/c2out pin is a schmitt trigger input and full cmos output driver. pin ra5 is multiplexed with the master clear module input. the ra5/mclr /v pp pin is a schmitt trigger input. pin ra6 is multiplexed with the oscillator module input and external oscillator output. pin ra7 is multiplexed with the oscillator module input and external oscillator input. pin ra6/osc2/clko and pin ra7/osc1/clki are schmitt trigger inputs and full cmos output drivers. pins ra<1:0> are multiplexed with analog inputs. pins ra<3:2> are multiplexed with analog inputs and com- parator outputs. on pic16f88 devices, pins ra<3:2> are also multiplexed with the v ref inputs. pins ra<3:0> have ttl inputs and full cmos output drivers. example 5-1: initializing porta table 5-1: porta functions note: on a power-on reset, the pins porta<4:0> are configured as analog inputs and read as ? 0 ?. banksel porta ; select bank of porta clrf porta ; initialize porta by ; clearing output ; data latches banksel ansel ; select bank of ansel movlw 0x00 ; configure all pins movwf ansel ; as digital inputs movlw 0xff ; value used to ; initialize data ; direction movwf trisa ; set ra<7:0> as inputs name bit# buffer function ra0/an0 bit 0 ttl input/output or analog input. ra1/an1 bit 1 ttl input/output or analog input. ra2/an2/cv ref /v ref - (2) bit 2 ttl input/output, analog input, v ref- or comparator v ref output. ra3/an3/v ref + (2) /c1out bit 3 ttl input/output, analog input, v ref+ or comparator output. ra4/an4 (2) /t0cki/c2out bit 4 st input/output, analog input, tmr0 external input or comparator output. ra5/mclr /v pp bit 5 st input, master clear (reset) or programming voltage input. ra6/osc2/clko bit 6 st input/output, connects to crystal or resonator, oscillator output or 1/4 the frequency of osc1 and denotes the instruction cycle in rc mode. ra7/osc1/clki bit 7 st/cmos (1) input/output, connects to crystal or resonator or oscillator input. legend: ttl = ttl input, st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured in rc oscillator mode and a cmos input otherwise. 2: pic16f88 only.
pic16f87/88 ds30487c-page 52 ? 2005 microchip technology inc. table 5-2: summary of registers associated with porta figure 5-1: block diagram of ra0/an0:ra1/an1 pins address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx 0000 (1) xxx0 0000 (2) uuuu 0000 (1) uuu0 0000 (2) 85h trisa trisa7 trisa6 trisa5 (3) porta data direction register 1111 1111 1111 1111 9fh adcon1 adfm adcs2 vcfg1 vcfg0 ? ? ? ? 0000 ---- 0000 ---- 9bh ansel (4) ? ans6 ans5 ans4 ans3 ans2 ans1 ans0 -111 1111 -111 1111 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by porta. note 1: this value applies only to the pic16f87. 2: this value applies only to the pic16f88. 3: pin 5 is an input only; the state of the tr isa5 bit has no effect and will always read ? 1 ?. 4: pic16f88 device only. data bus q d q ck p n wr porta wr trisa data latch tris latch rd trisa rd porta analog v ss v dd i/o pin q d q ck input mode d q en to comparator ttl input buffer v dd to a/d module channel input (pic16f88 only)
? 2005 microchip technology inc. ds30487c-page 53 pic16f87/88 figure 5-2: block di agram of ra3/an3/v ref +/c1out pin figure 5-3: block di agram of ra2/an2/cv ref /v ref - pin data bus q d q ck n wr porta wr trisa data latch tris latch rd trisa rd porta v ss ra3 pin q d q ck d q en to a/d module channel input (pic16f88 only) comparator 1 output comparator mode = 110 v dd analog input mode to a/d module channel v ref + input (pic16f88 only) p v dd to comparator v ss input buffer ttl data bus q d q ck p n wr porta wr trisa data latch tris latch rd trisa rd porta analog v ss v dd ra2 pin q d q ck d q en to comparator ttl input buffer input mode v dd to a/d module channel input (pic16f88 only) cvroe cv ref to a/d module v ref - (pic16f88 only)
pic16f87/88 ds30487c-page 54 ? 2005 microchip technology inc. figure 5-4: block diagram of ra4/an4/t0cki/c2out pin figure 5-5: block di agram of ra5/mclr /v pp pin data bus q d q ck n wr porta wr trisa data latch tris latch rd trisa rd porta v ss ra4 pin d q en tmr0 clock input schmitt trigger input buffer comparator 2 output comparator mode = 011 , 101 , 110 1 0 v dd analog input mode to a/d module channel input (pic16f88 only) p v dd q d q ck d q en mclr filter ra5/mclr /v pp pin rd port mclr circuit mclre mclre data bus rd tris schmitt trigger buffer v ss v ss schmitt trigger input buffer
? 2005 microchip technology inc. ds30487c-page 55 pic16f87/88 figure 5-6: block diagra m of ra6/osc2/clko pin data bus q d q ck p n wr porta wr trisa data latch tris latch rd trisa rd porta v ss v dd ra6/osc2/clko pin q d q ck d q en oscillator circuit from osc1 (f osc = 1x0 , 011 ) p n v ss v dd clko (f osc /4) v dd note 1: i/o pins have protection diodes to v dd and v ss . 2: clko signal is 1/4 of the f osc frequency. (f osc = 1x0 , 011 ) (f osc = 1x1 ) v ss schmitt trigger input buffer
pic16f87/88 ds30487c-page 56 ? 2005 microchip technology inc. figure 5-7: block diagra m of ra7/osc1/clki pin data bus q d q ck wr porta wr trisa data latch tris latch rd trisa rd porta d q en oscillator circuit ra7/osc1/clki pin (1) p n v ss v dd f osc = 10x v dd note 1: i/o pins have protection diodes to v dd and v ss . (f osc = 011 ) f osc = 10x from osc2 v ss schmitt trigger input buffer q d q ck
? 2005 microchip technology inc. ds30487c-page 57 pic16f87/88 5.2 portb and the trisb register portb is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit rbpu (option_reg<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. four of portb?s pins, rb7:rb4, have an interrupt-on- change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb7:rb4 pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are or?ed together to generate the rb port change interrupt with flag bit rbif (intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb. this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. rb0/int is an external interrupt input pin and is configured using the intedg bit (option_reg<6>). portb is multiplexed with several peripheral functions (see table 5-3). portb pins have schmitt trigger input buffers. when enabling peripheral functions, care should be taken in defining tris bits for each portb pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. since the tris bit override is in effect while the peripheral is enabled, read-modify- write instructions ( bsf, bcf, xorwf ) with trisb as the destination should be avoided. the user should refer to the corresponding peripheral section for the correct tris bit settings.
pic16f87/88 ds30487c-page 58 ? 2005 microchip technology inc. table 5-3: portb functions table 5-4: summary of registers associated with portb name bit# buffer function rb0/int/ccp1 (7) bit 0 ttl/st (1) input/output pin or external interrupt input. capture input/compare output/pwm output pin. internal software programmable weak pull-up. rb1/sdi/sda bit 1 ttl/st (5) input/output pin, spi? data input pin or i 2 c? data i/o pin. internal software programmable weak pull-up. rb2/sdo/rx/dt bit 2 ttl/st (4) input/output pin, spi data output pin. ausart asynchronous receive or synchronous data. internal software programmable weak pull-up. rb3/pgm/ccp1 (3,7) bit 3 ttl/st (2) input/output pin, programming in lvp mode or capture input/compare output/pwm output pin. internal software programmable weak pull-up. rb4/sck/scl bit 4 ttl/st (5) input/output pin or spi and i 2 c clock pin (with interrupt-on-change). internal software programmable weak pull-up. rb5/ss /tx/ck bit 5 ttl input/output pin or spi slave select pin (with interrupt-on-change). ausart asynchronous transmit or synchronous clock. internal software programmable weak pull-up. rb6/an5 (6) /pgc/ t1oso/t1cki bit 6 ttl/st (2) input/output pin, analog input (6) , serial programming clock (with interrupt-on-change), timer1 oscillator output pin or timer1 clock input pin. internal software programmable weak pull-up. rb7/an6 (6) /pgd/ t1osi bit 7 ttl/st (2) input/output pin, analog input (6) , serial programming data (with interrupt-on-change) or timer1 oscillator input pin. internal software programmable weak pull-up. legend: ttl = ttl input, st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode. 3: low-voltage icsp? programming (lvp) is enabled by default, which disables the rb3 i/o function. lvp must be disabled to enable rb3 as an i/o pin and allow maximum compatibility to the other 18-pin mid-range devices. 4: this buffer is a schmitt trigger input when configured for ccp or ssp mode. 5: this buffer is a schmitt trigger input when configured for spi or i 2 c mode. 6: pic16f88 only. 7: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 06h, 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx (1) 00xx xxxx (2) uuuu uuuu (1) 00uu uuuu (2) 86h, 186h trisb portb data direction register 1111 1111 1111 1111 81h, 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 9bh ansel (2) ? ans6 ans5 ans4 ans3 ans2 ans1 ans0 -111 1111 -111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by portb. note 1: this value applies only to the pic16f87. 2: this value applies only to the pic16f88.
? 2005 microchip technology inc. ds30487c-page 59 pic16f87/88 figure 5-8: block diagram of rb0/int/ccp1 (3) pin note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropria te tris bit(s) and clear the rbpu bit. 3: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register. data latch rbpu (2) p v dd q d ck q d ck q d en data bus wr portb wr trisb rd trisb rd portb weak pull-up rd portb i/o pin (1) ttl input buffer tris latch 0 1 ccp ccp1m<3:0> = 1000 , 1001 , 11xx and ccpmx = 1 to int0 or ccp ccp1m<3:0> = 000
pic16f87/88 ds30487c-page 60 ? 2005 microchip technology inc. figure 5-9: block diagra m of rb1/sdi/sda pin data latch rbpu (2) p v dd q d ck q d ck q d en data bus wr wr rd trisb rd portb weak pull-up rd portb sda (3) i/o pin (1) ttl input buffer schmitt trigger buffer tris latch note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 3: the sda schmitt conforms to the i 2 c specification. 1 0 sda output p n v ss v dd q sda drive port /sspen select i 2 c? mode sdi portb trisb
? 2005 microchip technology inc. ds30487c-page 61 pic16f87/88 figure 5-10: block diagra m of rb2/sdo/rx/dt pin dt sdo data latch rbpu (2) p v dd q d ck q d ck q d en data bus wr portb wr trisb rd trisb rd portb weak pull-up rd portb rx/dt i/o pin (1) ttl input buffer schmitt trigger buffer tris latch 1 0 p n v ss v dd q dt drive spen 1 0 sspen note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. sspen + spen
pic16f87/88 ds30487c-page 62 ? 2005 microchip technology inc. figure 5-11: block diagram of rb3/pgm/ccp1 (3) pin data latch rbpu (2) p v dd q d ck q d ck q d en data bus wr wr rd trisb rd portb weak pull-up rd portb i/o pin (1) ttl input buffer tris latch portb note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 3: the ccp1 pin is determined by the ccpmx bit in configuration word 1 register. 0 1 ccp to pgm or ccp ccp1m<3:0> = 1000 , 1001 , 11xx and ccpmx = 0 ccp1m<3:0> = 0100 , 0101 , 0110 , 0111 and ccpmx = 0 or lvp = 1 trisb
? 2005 microchip technology inc. ds30487c-page 63 pic16f87/88 figure 5-12: block diagra m of rb4/sck/scl pin data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr wr set rbif tris latch rd trisb rd portb rb7:rb4 pins weak pull-up rd portb latch ttl input buffer q3 q1 portb note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 3: the scl schmitt conforms to the i 2 c? specification. sck sck/scl 1 0 p ort /sspen scl (3) p n v ss v dd scl drive trisb
pic16f87/88 ds30487c-page 64 ? 2005 microchip technology inc. figure 5-13: block diagram of rb5/ss /tx/ck pin data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr wr set rbif tris latch rd trisb rd portb rb7:rb4 pins weak pull-up rd portb latch q3 q1 portb peripheral input p ort /sspen note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. trisb ttl input buffer
? 2005 microchip technology inc. ds30487c-page 65 pic16f87/88 figure 5-14: block diagram of rb6/an5 (3) /pgc/t1oso/t1cki pin data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr portb wr trisb set rbif tris latch rd trisb rd portb rb7:rb4 pins weak pull-up rd portb latch q3 q1 note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 3: pic16f88 devices only. pgc/t1cki analog ttl input buffer input mode t1oscen/icd/prog from t1osco output to a/d module channel input (pic16f88 only) analog input mode mode
pic16f87/88 ds30487c-page 66 ? 2005 microchip technology inc. figure 5-15: block diagram of rb7/an6 (3) /pgd/t1osi pin data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr t1oscen set rbif tris latch rd trisb rd portb rb7:rb4 pins weak pull-up rd portb latch q3 q1 portb note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit. 3: pic16f88 devices only. pgd pgd p ort /program mode/icd analog ttl input buffer input mode to t1osci input 1 0 pgd drven t1oscen wr trisb to a/d module channel input (pic16f88 only) 1 0 analog input mode
? 2005 microchip technology inc. ds30487c-page 67 pic16f87/88 6.0 timer0 module the timer0 module timer/counter has the following features:  8-bit timer/counter  readable and writable  8-bit software programmable prescaler  internal or external clock select  interrupt-on-overflow from ffh to 00h  edge select for external clock additional information on the timer0 module is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023). figure 6-1 is a block diagram of the timer0 module and the prescaler shared with the wdt. 6.1 timer0 operation timer0 operation is controlled through the option_reg register (see register 2-2). timer mode is selected by clearing bit t0cs (option_reg<5>). in timer mode, the timer0 module will increment every instruction cycle (without prescaler). if the tmr0 regis- ter is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting bit t0cs (option_reg<5>). in counter mode, timer0 will incre- ment, either on every rising or falling edge of pin ra4/ t0cki/c2out. the incrementing edge is determined by the timer0 source edge select bit, t0se (option_reg<4>). clearing bit t0se selects the rising edge. restrictions on the external clock input are discussed in detail in section 6.3 ?using timer0 with an external clock? . the prescaler is mutually, exclusively shared between the timer0 module and the watchdog timer. the prescaler is not readable or writable. section 6.4 ?prescaler? details the operation of the prescaler. 6.2 timer0 interrupt the tmr0 interrupt is generated when the tmr0 reg- ister overflows from ffh to 00h. this overflow sets bit tmr0if (intcon<2>). the interrupt can be masked by clearing bit tmr0ie (intcon<5>). bit tmr0if must be cleared in software by the timer0 module interrupt service routine before re-enabling this inter- rupt. the tmr0 interrupt cannot awaken the processor from sleep, since the timer is shut off during sleep. figure 6-1: block diagram of the timer0/wdt prescaler ra4/t0cki/c2out t0se pin m u x clko (= f osc /4) sync 2 cycles tmr0 reg 8-bit prescaler 8-to-1 mux m u x m u x psa 01 0 1 wdt time-out ps2:ps0 8 note: t0cs, t0se, psa and ps2:ps0 bits are (option_reg<5:0>). psa m u x 0 1 0 1 data bus set flag bit tmr0if on overflow 8 psa t0cs prescaler 31.25 khz wdt timer wdt enable bit 16-bit prescaler
pic16f87/88 ds30487c-page 68 ? 2005 microchip technology inc. 6.3 using timer0 with an external clock when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki, with the internal phase clocks, is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t0cki to be high for at least 2 t osc (and a small rc delay of 20 ns) and low for at least 2 t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. 6.4 prescaler there is only one prescaler available, which is mutually exclusively shared between the timer0 module and the watchdog timer. a prescaler assignment for the timer0 module means that the prescaler cannot be used by the watchdog timer and vice versa. this prescaler is not readable or writable (see figure 6-1). the psa and ps2:ps0 bits (option_reg<3:0>) determine the prescaler assignment and prescale ratio. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf 1 , movwf 1 , bsf 1 , x ....etc.) will clear the prescaler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. the prescaler is not readable or writable. register 6-1: option_reg: option control register (address 81h, 181h) note: although the prescaler can be assigned to either the wdt or timer0, but not both, a new divide counter is implemented in the wdt circuit to give multiple wdt time-out selections. this allows tmr0 and wdt to each have their own scaler. refer to section 15.12 ?watchdog timer (wdt)? for further details. note: writing to tmr0, when the prescaler is assigned to timer0, will clear the prescaler count but will not change the prescaler assignment. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit bit 6 intedg: interrupt edge select bit bit 5 t0cs : tmr0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: to avoid an unintended device reset, the instruction sequence shown in the ?picmicro ? mid-range mcu family reference manual? (ds33023) must be executed when changing the prescaler assignment from timer0 to the wdt. this sequence must be followed even if the wdt is disabled. 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
? 2005 microchip technology inc. ds30487c-page 69 pic16f87/88 example 6-1: changing the prescaler assignment from wdt to timer0 table 6-1: registers associated with timer0 clrwdt ; clear wdt and prescaler banksel option_reg ; select bank of option_reg movlw b'xxxx0xxx' ; select tmr0, new prescale movwf option_reg ; value and clock source address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 01h,101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 0bh,8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged. shaded cells ar e not used by timer0.
pic16f87/88 ds30487c-page 70 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 71 pic16f87/88 7.0 timer1 module the timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (tmr1h and tmr1l) which are readable and writable. the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the tmr1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing tmr1 interrupt enable bit, tmr1ie (pie1<0>). the timer1 oscillator can be used as a secondary clock source in low-power modes. when the t1run bit is set along with scs<1:0> = 01 , the timer1 oscillator is pro- viding the system clock. if the fail-safe clock monitor is enabled and the timer1 oscillator fails while providing the system clock, polling the t1run bit will indicate whether the clock is being provided by the timer1 oscillator or another source. timer1 can also be used to provide real-time clock (rtc) functionality to applications with only a minimal addition of external components and code overhead. 7.1 timer1 operation timer1 can operate in one of three modes: as a timer  as a synchronous counter  as an asynchronous counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). in timer mode, timer1 increments every instruction cycle. in counter mode, it increments on every rising edge of the external clock input. timer1 can be enabled/disabled by setting/clearing control bit, tmr1on (t1con<0>). timer1 also has an internal ?reset input?. this reset can be generated by the ccp1 module as the special event trigger (see section 9.1 ?capture mode? ). register 7-1 shows the timer1 control register. when the timer1 oscillator is enabled (t1oscen is set), the rb6/pgc/t1oso/t1cki and rb7/pgd/ t1osi pins become inputs. that is, the trisb<7:6> value is ignored and these pins read as ? 0 ?. additional information on timer modules is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023).
pic16f87/88 ds30487c-page 72 ? 2005 microchip technology inc. register 7-1: t1con: timer1 control regist er (address 10h) u-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 t1run : timer1 system clock status bit 1 = system clock is derived from timer1 oscillator 0 = system clock is derived from another source bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: timer1 oscillator enable control bit 1 = oscillator is enabled 0 = oscillator is shut off (the oscillator inverter is turned off to eliminate power drain) bit 2 t1sync : timer1 external clock input synchronization control bit tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from pin rb6/an5 (1) /pgc/t1oso/t1cki (on the rising edge) 0 = internal clock (f osc /4) note 1: available on pic16f88 devices only. bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 73 pic16f87/88 7.2 timer1 operation in timer mode timer mode is selected by clearing the tmr1cs (t1con<1>) bit. in this mode, the input clock to the timer is f osc /4. the synchronize control bit, t1sync (t1con<2>), has no effect since the internal clock is always in sync. 7.3 timer1 counter operation timer1 may operate in asynchronous or synchronous mode, depending on the setting of the tmr1cs bit. when timer1 is being incremented via an external source, increments occur on a rising edge. after timer1 is enabled in counter mode, the module must first have a falling edge before the counter begins to increment. 7.4 timer1 operation in synchronized counter mode counter mode is selected by setting bit tmr1cs. in this mode, the timer increments on every rising edge of clock input on pin rb7/pgd/t1osi when bit t1oscen is set, or on pin rb6/pgc/t1oso/t1cki when bit t1oscen is cleared. if t1sync is cleared, then the external clock input is synchronized with internal phase clocks. the synch- ronization is done after the prescaler stage. the prescaler stage is an asynchronous ripple counter. in this configuration, during sleep mode, timer1 will not increment even if the external clock is present since the synchronization circuit is shut off. the prescaler, however, will continue to increment. figure 7-1: timer1 incrementing edge figure 7-2: timer1 block diagram t1cki (default high) t1cki (default low) note: arrows indicate counter increments. tmr1h tmr1l t1osc t1sync tmr1cs t1ckps1:t1ckps0 q clock t1oscen enable oscillator (1) f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 t1osi t1oso/t1cki note 1: when the t1oscen bit is cleared, the inverter is turned off. this e liminates power drain. set flag bit tmr1if on overflow tmr1
pic16f87/88 ds30487c-page 74 ? 2005 microchip technology inc. 7.5 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt-on-overflow that will wake-up the processor. however, special precautions in software are needed to read/write the timer (see section 7.5.1 ?reading and writing timer1 in asynchronous counter mode? ). in asynchronous counter mode, timer1 cannot be used as a time base for capture or compare operations. 7.5.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l while the timer is running from an external asynchronous clock will ensure a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write conten- tion may occur by writing to the timer registers while the register is incrementing. this may produce an unpredictable value in the timer register. reading the 16-bit value requires some care. the example codes provided in example 7-1 and example 7-2 demonstrate how to write to and read timer1 while it is running in asynchronous mode. example 7-1: writing a 16-bit free running timer example 7-2: reading a 16-bit free running timer ; all interrupts are disabled clrf tmr1l ; clear low byte, ensures no rollover into tmr1h movlw hi_byte ; value to load into tmr1h movwf tmr1h, f ; write high byte movlw lo_byte ; value to load into tmr1l movwf tmr1h, f ; write low byte ; re-enable the interrupt (if required) continue ; continue with your code ; all interrupts are disabled movf tmr1h, w ; read high byte movwf tmph movf tmr1l, w ; read low byte movwf tmpl movf tmr1h, w ; read high byte subwf tmph, w ; sub 1st read with 2nd read btfsc status, z ; is result = 0 goto continue ; good 16-bit read ; tmr1l may have rolled over between the read of the high and low bytes. ; reading the high and low bytes now will read a good value. movf tmr1h, w ; read high byte movwf tmph movf tmr1l, w ; read low byte movwf tmpl ; re-enable the interrupt (if required) continue ; continue with your code
? 2005 microchip technology inc. ds30487c-page 75 pic16f87/88 7.6 timer1 oscillator a crystal oscillator circuit is built between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit t1oscen (t1con<3>). the oscilla- tor is a low-power oscillator, rated up to 32.768 khz. it will continue to run during all power-managed modes. it is primarily intended for a 32 khz crystal. the circuit for a typical lp oscillator is shown in figure 7-3. table 7-1 shows the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper oscillator start-up. figure 7-3: external components for the timer1 lp oscillator table 7-1: capacitor selection for the timer1 oscillator 7.7 timer1 oscillator layout considerations the timer1 oscillator circuit draws very little power during operation. due to the low-power nature of the oscillator, it may also be sensitive to rapidly changing signals in close proximity. the oscillator circuit, shown in figure 7-3, should be located as close as possible to the microcontroller. there should be no circuits passing within the oscillator circuit boundaries other than v ss or v dd . if a high-speed circuit must be located near the oscilla- tor, a grounded guard ring around the oscillator circuit, as shown in figure 7-4, may be helpful when used on a single-sided pcb or in addition to a ground plane. figure 7-4: oscillator circuit with grounded guard ring note: the timer1 oscillator shares the t1osi and t1oso pins with the pgd and pgc pins used for programming and debugging. when using the timer1 oscillator, in-circuit serial programming? (icsp?) may not function correctly (high voltage or low voltage), or the in-circuit debugger (icd) may not communicate with the controller. as a result of using either icsp or icd, the timer1 crystal may be damaged. if icsp or icd operations are required, the crystal should be disconnected from the circuit (disconnect either lead) or installed after programming. the oscillator loading capacitors may remain in-circuit during icsp or icd operation. pic16f87/88 t1osi t1oso c2 33 pf c1 33 pf xtal 32.768 khz note: see the notes with table 7-1 for additional information about capacitor selection. osc type freq c1 c2 lp 32 khz 33 pf 33 pf note 1: microchip suggests this value as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only. osc1 v ss osc2 rb7 rb6 rb5
pic16f87/88 ds30487c-page 76 ? 2005 microchip technology inc. 7.8 resetting timer1 using a ccp trigger output if the ccp1 module is configured in compare mode to generate a ?special event trigger? signal (ccp1m3:ccp1m0 = 1011) , the signal will reset timer1 and start an a/d conversion (if the a/d module is enabled). timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger from ccp1, the write will take precedence. in this mode of operation, the ccpr1h:ccpr1l register pair effectively becomes the period register for timer1. 7.9 resetting timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por, or any other reset, except by the ccp1 special event triggers. t1con register is reset to 00h on a power-on reset or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 7.10 timer1 prescaler the prescaler counter is cleared on writes to the tmr1h or tmr1l registers. 7.11 using timer1 as a real-time clock adding an external lp oscillator to timer1 (such as the one described in section 7.6 ?timer1 oscillator? ) gives users the option to include rtc functionality to their applications. this is accomplished with an inex- pensive watch crystal to provide an accurate time base and several lines of application code to calculate the time. when operating in sleep mode and using a battery or supercapacitor as a power source, it can completely eliminate the need for a separate rtc device and battery backup. the application code routine, rtcisr , shown in example 7-3, demonstrates a simple method to increment a counter at one-second intervals using an interrupt service routine. incrementing the tmr1 register pair to overflow triggers the interrupt and calls the routine, which increments the seconds counter by one; additional counters for minutes and hours are incremented as the previous counter overflows. since the register pair is 16 bits wide, counting up to overflow the register directly from a 32.768 khz clock would take 2 seconds. to force the overflow at the required one-second intervals, it is necessary to pre- load it; the simplest method is to set the msb of tmr1h with a bsf instruction. note that the tmr1l register is never preloaded or altered; doing so may introduce cumulative error over many cycles. for this method to be accurate, timer1 must operate in asynchronous mode and the timer1 overflow interrupt must be enabled (pie1<0> = 1 ), as shown in the routine, rtcinit . the timer1 oscillator must also be enabled and running at all times. note: the special event triggers from the ccp1 module will not set interrupt flag bit, tmr1if (pir1<0>).
? 2005 microchip technology inc. ds30487c-page 77 pic16f87/88 example 7-3: implementing a real-time clock using a timer1 interrupt service table 7-2: registers associated with timer1 as a timer/counter rtcinit banksel tmr1h movlw 0x80 ; preload tmr1 register pair movwf tmr1h ; for 1 second overflow clrf tmr1l movlw b?00001111? ; configure for external clock, movwf t1con ; asynchronous operation, external oscillator clrf secs ; initialize timekeeping registers clrf mins movlw .12 movwf hours banksel pie1 bsf pie1, tmr1ie ; enable timer1 interrupt return rtcisr banksel tmr1h bsf tmr1h, 7 ; preload for 1 sec overflow bcf pir1, tmr1if ; clear interrupt flag incf secs, f ; increment seconds movf secs, w sublw .60 btfss status, z ; 60 seconds elapsed? return ; no, done clrf seconds ; clear seconds incf mins, f ; increment minutes movf mins, w sublw .60 btfss status, z ; 60 seconds elapsed? return ; no, done clrf mins ; clear minutes incf hours, f ; increment hours movf hours, w sublw .24 btfss status, z ; 24 hours elapsed? return ; no, done clrf hours ; clear hours return ; done address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on -000 0000 -uuu uuuu legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 78 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 79 pic16f87/88 8.0 timer2 module timer2 is an 8-bit timer with a prescaler and a postscaler. it can be used as the pwm time base for the pwm mode of the ccp1 module. the tmr2 register is readable and writable and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits t2ckps1:t2ckps0 (t2con<1:0>). the timer2 module has an 8-bit period register, pr2. timer2 increments from 00h until it matches pr2 and then resets to 00h on the next increment cycle. pr2 is a readable and writable register. the pr2 register is initialized to ffh upon reset. the match output of tmr2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr2 interrupt (latched in flag bit tmr2if (pir1<1>)). timer2 can be shut off by clearing control bit tmr2on (t2con<2>) to minimize power consumption. register 8-1 shows the timer2 control register. additional information on timer modules is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023). 8.1 timer2 prescaler and postscaler the prescaler and postscaler counters are cleared when any of the following occurs:  a write to the tmr2 register  a write to the t2con register  any device reset (power-on reset, mclr , wdt reset or brown-out reset) tmr2 is not cleared when t2con is written. 8.2 output of tmr2 the output of tmr2 (before the postscaler) is fed to the synchronous serial port module (ssp) which optionally uses it to generate a shift clock. figure 8-1: timer2 block diagram comparator tmr2 sets flag tmr2 reg output (1) reset postscaler prescaler pr2 reg 2 f osc /4 1:1 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if note 1: tmr2 register output can be software selected by the ssp module as a baud clock. to
pic16f87/88 ds30487c-page 80 ? 2005 microchip technology inc. register 8-1: t2con: timer2 control regist er (address 12h) table 8-1: registers associated with timer2 as a timer/counter u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-3 toutps<3:0>: timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale 0010 = 1:3 postscale    1111 = 1:16 postscale bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 11h tmr2 timer2 module register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
? 2005 microchip technology inc. ds30487c-page 81 pic16f87/88 9.0 capture/compare/pwm (ccp) module the capture/compare/pwm (ccp) module contains a 16-bit register that can operate as a:  16-bit capture register  16-bit compare register  pwm master/slave duty cycle register. table 9-1 shows the timer resources of the ccp module modes. capture/compare/pwm register 1 (ccpr1) is com- prised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. the special event trigger is generated by a compare match which will reset timer1 and start an a/d conversion (if the a/d module is enabled). the ccp module?s input/output pin (ccp1) can be configured as rb0 or rb3. this selection is set in bit 12 (ccpmx) of the configuration word. additional information on the ccp module is available in the ? picmicro ? mid-range mcu family reference manual ? (ds33023) and in application note an594, ? using the ccp module(s) ? (ds00594). table 9-1: ccp mode ? timer resource register 9-1: ccp1con: capture/compare/pwm control register 1 (address 17h) ccp mode timer resource capture compare pwm timer1 timer1 timer2 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-4 ccp1x:ccp1y: pwm least significant bits capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr1l. bit 3-0 ccp1m<3:0>: ccp1 mode select bits 0000 = capture/compare/pwm disabled (resets ccp1 module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit is set, ccp1 pin is unaffected); ccp1 resets tmr1 and starts an a/d conversion (if a/d module is enabled) 11xx =pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 82 ? 2005 microchip technology inc. 9.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on the ccp1 pin. an event is defined as:  every falling edge  every rising edge  every 4th rising edge  every 16th rising edge an event is selected by control bits ccp1m3:ccp1m0 (ccp1con<3:0>). when a capture is made, the inter- rupt request flag bit, ccp1if (pir1<2>), is set. it must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value is overwritten by the new captured value. 9.1.1 ccp pin configuration in capture mode, the ccp1 pin should be configured as an input by setting the trisb bit. figure 9-1: capture mode operation block diagram 9.1.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 9.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit, ccp1if, following any such change in operating mode. 9.1.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m3:ccp1m0. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore, the first capture may be from a non-zero prescaler. example 9-1 shows the recom- mended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 9-1: changing between capture prescalers note 1: if the ccp1 pin is configured as an output, a write to the port can cause a capture condition. 2: the trisb bit (0 or 3) is dependent upon the setting of configuration bit 12 (ccpmx). ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> ccp1 pin prescaler 1, 4, 16 and edge detect clrf ccp1con ;turn ccp module off movlw new_capt_ps ;load the w reg with ;the new prescaler ;move value and ccp on movwf ccp1con ;load ccp1con with this ;value
? 2005 microchip technology inc. ds30487c-page 83 pic16f87/88 9.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the ccp1 pin is:  driven high driven low  remains unchanged the action on the pin is based on the value of control bits ccp1m3:ccp1m0 (ccp1con<3:0>). at the same time, interrupt flag bit, ccp1if, is set. figure 9-2: compare mode operation block diagram 9.2.1 ccp pin configuration the user must configure the ccp1 pin as an output by clearing the trisb bit. 9.2.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 9.2.3 software interrupt mode when generate software interrupt is chosen, the ccp1 pin is not affected. only a ccp interrupt is generated (if enabled). 9.2.4 special event trigger in this mode, an internal hardware trigger is generated that may be used to initiate an action. the special event trigger output of ccp1 resets the tmr1 register pair and starts an a/d conversion (if the a/d module is enabled). this allows the ccpr1 register to effectively be a 16-bit programmable period register for timer1. table 9-2: registers associated with capture, compare and timer1 ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic special event trigger set flag bit ccp1if (pir1<2>) match ccp1 pin trisb ccp1con<3:0> mode select output enable special event trigger will:  reset timer1 but not set interrupt flag bit, tmr1if (pir1<0>)  set bit go/done (adcon0<2>) which starts an a/d conversion note 1: clearing the ccp1con register will force the ccp1 compare output latch to the default low level. this is not the data latch. 2: the trisb bit (0 or 3) is dependent upon the setting of configuration bit 12 (ccpmx). note: the special event trigger from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh,8bh 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 86h trisb portb data direction register 1111 1111 1111 1111 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on -000 0000 -uuu uuuu 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by capture and timer1. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 84 ? 2005 microchip technology inc. 9.3 pwm mode in pulse-width modulation (pwm) mode, the ccp1 pin produces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with the portb data latch, the trisb bit must be cleared to make the ccp1 pin an output. figure 9-3 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 9.3.3 ?setup for pwm operation? . figure 9-3: simplified pwm block diagram a pwm output (figure 9-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 9-4: pwm output 9.3.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula. equation 9-1: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: tmr2 is cleared  the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is latched from ccpr1l into ccpr1h 9.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the ccpr1l contains the eight msbs and the ccp1con<5:4> bits contain the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time. equation 9-2: ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the ccpr1h and 2-bit latch match tmr2, concatenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portb i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisb ccp1 pin note 1: 8-bit timer is concatenated with 2-bit internal q clock, or 2 bits of the prescaler, to create 10-bit time base. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 note: the timer2 postscaler (see section 8.0 ?timer2 module? ) is not used in the deter- mination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. pwm period = [(pr2) + 1] ? 4  t osc  (tmr2 prescale value) pwm duty cycle = (ccpr1l:ccp1con<5:4>)  t osc  (tmr2 prescale value)
? 2005 microchip technology inc. ds30487c-page 85 pic16f87/88 the maximum pwm resolution (bits) for a given pwm frequency is given by the following formula. equation 9-3: 9.3.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the trisb bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. table 9-3: example pwm frequencies and resolutions at 20 mhz table 9-4: registers associated with pwm and timer2 note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. log ( f pwm log(2) f osc ) bits = resolution note: the trisb bit (0 or 3) is dependant upon the setting of configuration bit 12 (ccpmx). pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12 khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xff 0xff 0xff 0x3f 0x1f 0x17 maximum resolution (bits) 10 10 10 8 7 6.6 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh,8bh 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 86h trisb portb data direction register 1111 1111 1111 1111 11h tmr2 timer2 module register 0000 0000 0000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by pwm and timer2. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 86 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 87 pic16f87/88 10.0 synchronous serial port (ssp) module 10.1 ssp module overview the synchronous serial port (ssp) module is a serial interface useful for communicating with other periph- eral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, display drivers, a/d converters, etc. the ssp module can operate in one of two modes:  serial peripheral interface (spi?)  inter-integrated circuit (i 2 c?) an overview of i 2 c operations and additional informa- tion on the ssp module can be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023). refer to application note an578, ?use of the ssp module in the i 2 c? multi-master environment? (ds00578). 10.2 spi mode this section contains register definitions and operational characteristics of the spi module. spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. to accomplish communication, typically three pins are used:  serial data out (sdo) rb2/sdo/rx/dt  serial data in (sdi) rb1/sdi/sda  serial clock (sck) rb4/sck/scl additionally, a fourth pin may be used when in a slave mode of operation:  slave select (ss ) rb5/ss/ tx/ck when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits in the sspcon register (sspcon<5:0>) and the sspstat register (sspstat<7:6>). these control bits allow the following to be specified:  master mode (sck is the clock output)  slave mode (sck is the clock input)  clock polarity (idle state of sck)  clock edge (output data on rising/falling edge of sck)  clock rate (master mode only)  slave select mode (slave mode only) note: before enabling the module in spi slave mode, the state of the clock line (sck) must match the polarity selected for the idle state. the clock line can be observed by reading the sck pin. the polarity of the idle state is determined by the ckp bit (sspcon<4>).
pic16f87/88 ds30487c-page 88 ? 2005 microchip technology inc. register 10-1: sspstat: synchronous serial port status register (address 94h) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a p (1) s (1) r/w ua bf bit 7 bit 0 bit 7 smp: spi data input sample phase bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time (microwire) spi slave mode: this bit must be cleared when spi is used in slave mode. i 2 c mode: this bit must be maintained clear. bit 6 cke: spi clock edge select bit 1 = transmit occurs on transition from active to idle clock state 0 = transmit occurs on transition from idle to active clock state note: polarity of clock state is set by the ckp bit (sspcon<4>). bit 5 d/a : data/address bit (i 2 c mode only) in i 2 c slave mode: 1 = indicates that the last byte received was data 0 = indicates that the last byte received was address bit 4 p: stop bit (1) (i 2 c mode only) 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last bit 3 s: start bit (1) (i 2 c mode only) 1 = indicates that a start bit has been detected last (this bit is ? 0 ? on reset) 0 = start bit was not detected last bit 2 r/w : read/write information bit (i 2 c mode only) holds the r/w bit information following the last address match and is only valid from address match to the next start bit, stop bit or ack bit. 1 =read 0 = write bit 1 ua: update address bit (10-bit i 2 c mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit receive (spi and i 2 c modes): 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty transmit (in i 2 c mode only): 1 = transmit in progress, sspbuf is full (8 bits) 0 = transmit complete, sspbuf is empty note 1: this bit is cleared when the ssp module is disabled (i.e., the sspen bit is cleared). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 89 pic16f87/88 register 10-2: sspcon: synchronous serial port control register (address 14h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen (1) ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol: write collision detect bit 1 = an attempt to write the sspbuf register failed because the ssp module is busy (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit in spi mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode. the user must read the sspbuf, even if only transmitting data, to avoid setting overflow. in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register. 0 = no overflow in i 2 c mode: 1 = a byte is received while the sspbuf register is still holding the previous byte. sspov is a ?don?t care? in transmit mode. sspov must be cleared in software in either mode. 0 = no overflow bit 5 sspen: synchronous serial port enable bit (1) in spi mode: 1 = enables serial port and configures sck, sdo and sdi as serial port pins 0 = disables serial port and configures these pins as i/o port pins in i 2 c mode : 1 = enables the serial port and configures the sda and scl pins as serial port pins 0 = disables serial port and configures these pins as i/o port pins note 1: in both modes, when enabled, these pins must be properly configured as input or output. bit 4 ckp: clock polarity select bit in spi mode: 1 = transmit happens on falling edge, receive on rising edge. idle state for clock is a high level. 0 = transmit happens on rising edge, receive on falling edge. idle state for clock is a low level. in i 2 c slave mode: sck release control 1 = enable clock 0 = holds clock low (clock stretch). (used to ensure data setup time.) bit 3-0 sspm<3:0>: synchronous serial port mode select bits 0000 = spi master mode, clock = osc/4 0001 = spi master mode, clock = osc/16 0010 = spi master mode, clock = osc/64 0011 = spi master mode, clock = tmr2 output/2 0100 = spi slave mode, clock = sck pin. ss pin control enabled. 0101 = spi slave mode, clock = sck pin. ss pin control disabled. ss can be used as i/o pin. 0110 = i 2 c slave mode, 7-bit address 0111 = i 2 c slave mode, 10-bit address 1011 = i 2 c firmware controlled master mode (slave idle) 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled 1000 , 1001 , 1010 , 1100 , 1101 = reserved legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 90 ? 2005 microchip technology inc. figure 10-1: ssp block diagram (spi? mode) to enable the serial port, ssp enable bit, sspen (sspcon<5>), must be set. to reset or reconfigure spi mode, clear bit sspen, reinitialize the sspcon register and then set bit sspen. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port function, they must have their data direction bits (in the trisb register) appropriately programmed. that is:  sdi must have trisb<1> set  sdo must have trisb<2> cleared  sck (master mode) must have trisb<4> cleared  sck (slave mode) must have trisb<4> set ss must have trisb<5> set table 10-1: registers associated with spi? operation read write internal data bus rb1/sdi/sda rb2/sdo/rx/dt rb5/ss / rb4/sck/ sspsr reg sspbuf reg sspm3:sspm0 bit0 shift clock ss control enable edge select clock select tmr2 output t cy prescaler 4, 16, 64 trisb<4> 2 edge select 2 4 scl tx/ck note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke = 1 , then the ss pin control must be enabled. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh,8bh 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 86h trisb portb data direction register 1111 1111 1111 1111 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 94h sspstat smp cke d/a p s r/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the ssp in spi? mode. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
? 2005 microchip technology inc. ds30487c-page 91 pic16f87/88 figure 10-2: spi? mode timing (master mode) figure 10-3: spi? mode timing (slave mode with cke = 0 ) figure 10-4: spi? mode timing (slave mode with cke = 1 ) sck (ckp = 0 , sdi (smp = 0 ) sspif bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sdi (smp = 1 ) sck (ckp = 0 , sck (ckp = 1 , sck (ckp = 1 , sdo bit 7 bit 7 bit 0 bit 0 cke = 0 ) cke = 1 ) cke = 0 ) cke = 1 ) sck (ckp = 0 ) sdi (smp = 0 ) sspif bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sck (ckp = 1 ) sdo bit 7 bit 0 ss (optional) sck (ckp = 0 ) sdi (smp = 0 ) sspif bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sck (ckp = 1 ) sdo bit 7 bit 0 ss
pic16f87/88 ds30487c-page 92 ? 2005 microchip technology inc. 10.3 ssp i 2 c mode operation the ssp module in i 2 c mode fully implements all slave functions, except general call support and provides interrupts on start and stop bits in hardware to facilitate firmware implementations of the master functions. the ssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer. these are the rb4/ sck/scl pin, which is the clock (scl) and the rb1/ sdi/sda pin, which is the data (sda). the user must configure these pins as inputs or outputs through the trisb<4,1> bits. to ensure proper communication of the i 2 c slave mode, the tris bits (trisx [sda, scl]) corresponding to the i 2 c pins must be set to ? 1 ?. if any tris bits (trisx<7:0>) of the port containing the i 2 c pins (portx [sda, scl]) are changed in software during i 2 c communication using a read-modify-write instruction ( bsf , bcf ), then the i 2 c mode may stop functioning properly and i 2 c communication may suspend. do not change any of the trisx bits (tris bits of the port containing the i 2 c pins) using the instruction bsf or bcf during i 2 c communica- tion. if it is absolutely necessary to change the trisx bits during communication, the following method can be used: example 10-1: the ssp module functions are enabled by setting ssp enable bit, sspen (sspcon<5>). figure 10-5: ssp block diagram (i 2 c? mode) the ssp module has five registers for i 2 c operation:  ssp control register (sspcon)  ssp status register (sspstat)  serial receive/transmit buffer register (sspbuf)  ssp shift register (sspsr) ? not directly accessible  ssp address register (sspadd) the sspcon register allows control of the i 2 c opera- tion. four mode selection bits (sspcon<3:0>) allow one of the following i 2 c modes to be selected: i 2 c slave mode (7-bit address) i 2 c slave mode (10-bit address) i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled to support firmware controlled master mode i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled to support firmware controlled master mode i 2 c firmware controlled master mode operation with start and stop bit interrupts enabled; slave is idle selection of any i 2 c mode, with the sspen bit set, forces the scl and sda pins to be open-drain, pro- vided these pins are programmed to inputs by setting the appropriate trisb bits. pull-up resistors must be provided externally to the scl and sda pins for proper operation of the i 2 c module. additional information on ssp i 2 c operation may be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023). movf trisc, w ; example for an 18-pin part such as the pic16f818/819 iorlw 0x18 ; ensures <4:3> bits are ?11? andlw b?11111001? ; sets <2:1> as output, but will not alter other bits ; user can use their own logic here, such as iorlw, xorlw and andlw movwf trisc read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) rb4/sck/ rb1/ shift clock msb sdi/ lsb sda scl
? 2005 microchip technology inc. ds30487c-page 93 pic16f87/88 10.3.1 slave mode in slave mode, the scl and sda pins must be config- ured as inputs (trisb<4,1> set). the ssp module will override the input state with the output data when required (slave-transmitter). when an address is matched, or the data transfer after an address match is received, the hardware automati- cally will generate the acknowledge (ack ) pulse and then load the sspbuf register with the received value currently in the sspsr register. either or both of the following conditions will cause the ssp module not to give this ack pulse: a) the buffer full bit, bf (sspstat<0>), was set before the transfer was received. b) the overflow bit, sspov (sspcon<6>), was set before the transfer was received. in this case, the sspsr register value is not loaded into the sspbuf, but bit sspif (pir1<3>) is set. table 10-2 shows what happens when a data transfer byte is received, given the status of bits bf and sspov. the shaded cells show the condition where user software did not properly clear the overflow condi- tion. flag bit, bf, is cleared by reading the sspbuf register while bit, sspov, is cleared through software. the scl clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the ssp module, are shown in timing parameter #100 and parameter #101. 10.3.1.1 addressing once the ssp module has been enabled, it waits for a start condition to occur. following the start condition, the eight bits are shifted into the sspsr register. all incoming bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is compared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match and the bf and sspov bits are clear, the following events occur: a) the sspsr register value is loaded into the sspbuf register. b) the buffer full bit, bf, is set. c) an ack pulse is generated. d) ssp interrupt flag bit, sspif (pir1<3>), is set (interrupt is generated if enabled) ? on the falling edge of the ninth scl pulse. in 10-bit address mode, two address bytes need to be received by the slave device. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspstat<2>) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 1111 0 a9 a8 0 ?, where a9 and a8 are the two msbs of the address. the sequence of events for 10-bit address mode is as follows, with steps 7-9 for slave transmitter: 1. receive first (high) byte of address (bits sspif, bf and ua (sspstat<1>) are set). 2. update the sspadd register with second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf and ua are set). 5. update the sspadd register with the first (high) byte of address; if match releases scl line, this will clear bit ua. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif. 10.3.1.2 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register. when the address byte overflow condition exists, then a no acknowledge (ack ) pulse is given. an overflow condition is indicated if either bit, bf (sspstat<0>), is set or bit, sspov (sspcon<6>), is set. an ssp interrupt is generated for each data transfer byte. flag bit, sspif (pir1<3>), must be cleared in software. the sspstat register is used to determine the status of the byte. 10.3.1.3 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit and pin rb4/sck/scl is held low. the transmit data must be loaded into the sspbuf register which also loads the sspsr register. then, pin rb4/sck/scl should be enabled by setting bit ckp (sspcon<4>). the master device must mon- itor the scl pin prior to asserting another clock pulse. the slave devices may be holding off the master device by stretching the clock. the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time (figure 10-7).
pic16f87/88 ds30487c-page 94 ? 2005 microchip technology inc. an ssp interrupt is generated for each data transfer byte. flag bit, sspif, must be cleared in software and the sspstat register is used to determine the status of the byte. flag bit, sspif, is set on the falling edge of the ninth clock pulse. as a slave transmitter, the ack pulse from the master receiver is latched on the rising edge of the ninth scl input pulse. if the sda line was high (not ack ), then the data transfer is complete. when the ack is latched by the slave device, the slave logic is reset (resets sspstat register) and the slave device then monitors for another occurrence of the start bit. if the sda line was low (ack ), the transmit data must be loaded into the sspbuf register which also loads the sspsr register. then, pin rb4/sck/scl should be enabled by setting bit ckp. table 10-2: data transfer received byte actions figure 10-6: i 2 c? waveforms for reception (7-bit address) figure 10-7: i 2 c? waveforms for transmission (7-bit address) status bits as data transfer is received sspsr sspbuf generate ack pulse set sspif bit (ssp interrupt occurs if enabled) bf sspov 00 yes yes yes 10 no no yes 11 no no yes 0 1 no no yes note 1: shaded cells show the conditions where the user software did not properly clear the overflow condition. p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 56 7 89 123 4 bus master terminates transfer bit sspov is set because the sspbuf register is still full cleared in software sspbuf register is read ack receiving data receiving data d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 0 receiving address sspif (pir1<3>) bf (sspstat<0>) sspov (sspcon<6>) ack ack is not sent sda scl sspif (pir1<3>) bf (sspstat<0>) ckp (sspcon<4>) a7 a6 a5 a4 a3 a2 a1 ack d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data r/w = 1 receiving address 123456789 123456789 p cleared in software sspbuf is written in software from ssp interrupt service routine set bit after writing to sspbuf s data is sampled scl held low while cpu responds to sspif (the sspbuf must be written to before the ckp bit can be set)
? 2005 microchip technology inc. ds30487c-page 95 pic16f87/88 10.3.2 master mode operation master mode operation is supported in firmware using interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset, or when the ssp module is dis- abled. the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when the p bit is set, or the bus is idle and both the s and p bits are clear. in master mode operation, the scl and sda lines are manipulated in firmware by clearing the corresponding trisb<4,1> bit(s). the output level is always low, irre- spective of the value(s) in portb<4,1>. so, when transmitting data, a ? 1 ? data bit must have the trisb<1> bit set (input) and a ? 0 ? data bit must have the trisb<1> bit cleared (output). the same scenario is true for the scl line with the trisb<4> bit. pull-up resistors must be provided externally to the scl and sda pins for proper operation of the i 2 c module. the following events will cause the ssp interrupt flag bit, sspif, to be set (ssp interrupt if enabled):  start condition  stop condition  data transfer byte transmitted/received master mode operation can be done with either the slave mode idle (sspm3:sspm0 = 1011 ), or with the slave mode active. when both master mode operation and slave modes are used, the software needs to differentiate the source(s) of the interrupt. for more information on master mode operation, see application note an554, ?software implementation of i 2 c? bus master? . 10.3.3 multi-master mode operation in multi-master mode operation, the interrupt genera- tion on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset, or when the ssp module is disabled. the stop (p) and start (s) bits will toggle based on the start and stop conditions. control of the i 2 c bus may be taken when bit p (sspstat<4>) is set, or the bus is idle and both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will generate the interrupt when the stop condition occurs. in multi-master mode operation, the sda line must be monitored to see if the signal level is the expected out- put level. this check only needs to be done when a high level is output. if a high level is expected and a low level is present, the device needs to release the sda and scl lines (set trisb<4,1>). there are two stages where this arbitration can be lost:  address transfer  data transfer when the slave logic is enabled, the slave device continues to receive. if arbitration was lost during the address transfer stage, communication to the device may be in progress. if addressed, an ack pulse will be generated. if arbitration was lost during the data transfer stage, the device will need to retransfer the data at a later time. for more information on multi-master mode operation, see application note an578, ?use of the ssp module in the of i 2 c? multi-master environment? . table 10-3: registers associated with i 2 c? operation address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 93h sspadd synchronous serial port (i 2 c mode) address register 0000 0000 0000 0000 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 94h sspstat smp (2) cke (2) d/a psr/w ua bf 0000 0000 0000 0000 86h trisb portb data direction register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented locations read as ? 0 ?. shaded cells are not used by ssp module in spi? mode. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. 2: maintain these bits clear in i 2 c? mode.
pic16f87/88 ds30487c-page 96 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 97 pic16f87/88 11.0 addressable universal synchronous asynchronous receiver transmitter (ausart) the addressable universal synchronous asynchronous receiver transmitter (ausart) module is one of the two serial i/o modules. (ausart is also known as a serial communications interface or sci.) the ausart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers, or it can be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the ausart can be configured in the following modes:  asynchronous (full-duplex)  synchronous ? master (half-duplex)  synchronous ? slave (half-duplex) bit spen (rcsta<7>) and bits trisb<5,2> have to be set in order to configure pins, rb5/ss /tx/ck and rb2/sdo/rx/dt, as the addressable universal synchronous asynchronous receiver transmitter. the ausart module also has a multi-processor communication capability, using 9-bit address detection. register 11-1: txsta: transmit status and control register (address 98h) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync ? brgh trmt tx9d bit 7 bit 0 bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9 : 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen : transmit enable bit 1 = transmit enabled 0 = transmit disabled note: sren/cren overrides txen in sync mode. bit 4 sync : ausart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented: read as ? 0 ? bit 2 brgh : high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt : transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data, can be parity bit legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 98 ? 2005 microchip technology inc. register 11-2: rcsta: receive status and control register (address 18h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 bit 7 spen: serial port enable bit 1 = serial port enabled (configures rb2/sdo/rx/dt and rb5/ss /tx/ck pins as serial port pins) 0 = serial port disabled bit 6 rx9 : 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren : single receive enable bit asynchronous mode: don?t care. synchronous mode ? m aster: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? s lave: don?t care. bit 4 cren : continuous receive enable bit asynchronous mode: 1 = enables continuous receive 0 = disables continuous receive synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ): 1 = enables address detection, enables interrupt and load of the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit bit 2 ferr : framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr : overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data (can be parity bit, but must be calculated by user firmware) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 99 pic16f87/88 11.1 ausart baud rate generator (brg) the brg supports both the asynchronous and synchronous modes of the ausart. it is a dedicated 8-bit baud rate generator. the spbrg register controls the period of a free running 8-bit timer. in asyn- chronous mode, bit brgh (txsta<2>) also controls the baud rate. in synchronous mode, bit brgh is ignored. table 11-1 shows the formula for computation of the baud rate for different ausart modes which only apply in master mode (internal clock). given the desired baud rate and f osc , the nearest integer value for the spbrg register can be calculated using the formula in table 11-1. from this, the error in baud rate can be determined. it may be advantageous to use the high baud rate (brgh = 1 ) even for slower baud clocks. this is because the f osc /(16(x + 1)) equation can reduce the baud rate error in some cases. writing a new value to the spbrg register causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 11.1.1 ausart and intrc operation the pic16f87/88 has an 8 mhz intrc that can be used as the system clock, thereby eliminating the need for external components to provide the clock source. when the intrc provides the system clock, the ausart module will also use the intrc as its system clock. table 11-1 shows some of the intrc frequencies that can be used to generate the ausart module?s baud rate. 11.1.2 low-power mode operation the system clock is used to generate the desired baud rate; however, when a low-power mode is entered, the low-power clock source may be operating at a different frequency than in full power execution. in sleep mode, no clocks are present. this may require the value in spbrg to be adjusted. 11.1.3 sampling the data on the rb2/sdo/rx/dt pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 11-1: baud rate formula table 11-2: registers associated with baud rate generator sync brgh = 0 (low speed) brgh = 1 (high speed) 0 1 (asynchronous) baud rate = f osc /(64(x + 1)) (synchronous) baud rate = f osc /(4(x + 1)) baud rate = f osc /(16(x + 1)) n/a legend: x = value in spbrg (0 to 255) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used by the brg.
pic16f87/88 ds30487c-page 100 ? 2005 microchip technology inc. table 11-3: baud rates for asynchronous mode (brgh = 0 ) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3????????? 1.2 1.221 +1.75 255 1.202 +0.17 207 1.202 +0.17 129 2.4 2.404 +0.17 129 2.404 +0.17 103 2.404 +0.17 64 9.6 9.766 +1.73 31 9.615 +0.16 25 9.766 +1.73 15 19.2 19.531 + 1.72 15 19.231 +0.16 12 19.531 +1.72 7 28.8 31.250 +8.51 9 27.778 -3.55 8 31.250 +8.51 4 33.6 34.722 +3.34 8 35.714 +6.29 6 31.250 -6.99 4 57.6 62.500 +8.51 4 62.500 +8.51 3 52.083 -9.58 2 high 1.221 ? 255 0.977 ? 255 0.610 ? 255 low 312.500 ? 0 250.000 ? 0 156.250 ? 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3 0.300 0 207 0.3 0 191 1.2 1.202 +0.17 51 1.2 0 47 2.4 2.404 +0.17 25 2.4 0 23 9.6 8.929 +6.99 6 9.6 0 5 19.2 20.833 +8.51 2 19.2 0 2 28.8 31.250 +8.51 1 28.8 0 1 33.6 ? ? ? ? ? ? 57.6 62.500 +8.51 0 57.6 0 0 high 0.244 ? 255 0.225 ? 255 low 62.500 ? 0 57.6 ? 0 table 11-4: baud rates for asynchronous mode (brgh = 1 ) baud rate (k) f osc = 20 mhz f osc = 16 mhz f osc = 10 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3????????? 1.2????????? 2.4 ? ? ? ? ? ? 2.441 +1.71 255 9.6 9.615 +0.16 129 9.615 +0.16 103 9.615 +0.16 64 19.2 19.231 +0.16 64 19.231 +0.16 51 19.531 +1.72 31 28.8 29.070 +0.94 42 29.412 +2.13 33 28.409 -1.36 21 33.6 33.784 +0.55 36 33.333 -0.79 29 32.895 -2.10 18 57.6 59.524 +3.34 20 58.824 +2.13 16 56.818 -1.36 10 high 4.883 ? 255 3.906 ? 255 2.441 ? 255 low 1250.000 ? 0 1000.000 ? 0 625.000 ? 0 baud rate (k) f osc = 4 mhz f osc = 3.6864 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3?????? 1.2 1.202 +0.17 207 1.2 0 191 2.4 2.404 +0.17 103 2.4 0 95 9.6 9.615 +0.16 25 9.6 0 23 19.2 19.231 +0.16 12 19.2 0 11 28.8 27.798 -3.55 8 28.8 0 7 33.6 35.714 +6.29 6 32.9 -2.04 6 57.6 62.500 +8.51 3 57.6 0 3 high 0.977 ? 255 0.9 ? 255 low 250.000 ? 0 230.4 ? 0
? 2005 microchip technology inc. ds30487c-page 101 pic16f87/88 table 11-5: intrc baud rates fo r asynchronous mode (brgh = 0 ) baud rate (k) f osc = 8 mhz f osc = 4 mhz f osc = 2 mhz f osc = 1 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3 na ? ? 0.300 0 207 0.300 0 103 0.300 0 51 1.2 1.202 +0.16 103 1.202 +0.16 51 1.202 +0.16 25 1.202 +0.16 12 2.4 2.404 +0.16 51 2.404 +0.16 25 2.404 +0.16 12 2.232 -6.99 6 9.6 9.615 +0.16 12 8.929 -6.99 6 10.417 +8.51 2 na ? ? 19.2 17.857 -6.99 6 20.833 +8.51 2 na ? ? na ? ? 28.8 31.250 +8.51 3 31.250 +8.51 1 31.250 +8.51 0 na ? ? 38.4 41.667 +8.51 2 na ? ? na ? ? na ? ? 57.6 62.500 +8.51 1 62.500 8.51 0 na ? ? na ? ? table 11-6: intrc baud rates fo r asynchronous mode (brgh = 1 ) baud rate (k) f osc = 8 mhz f osc = 4 mhz f osc = 2 mhz f osc = 1 mhz kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) kbaud % error spbrg value (decimal) 0.3 na ? ? na ? ? na ? ? 0.300 0 207 1.2 na ? ? 1.202 +0.16 207 1.202 +0.16 103 1.202 +0.16 51 2.4 2.404 +0.16 207 2.404 +0.16 103 2.404 +0.16 51 2.404 +0.16 25 9.6 9.615 +0.16 51 9.615 +0.16 25 9.615 +0.16 12 8.929 -6.99 6 19.2 19.231 +0.16 25 19.231 +0.16 12 17.857 -6.99 6 20.833 +8.51 2 28.8 29.412 +2.12 16 27.778 -3.55 8 31.250 +8.51 3 31.250 +8.51 1 38.4 38.462 +0.16 12 35.714 -6.99 6 41.667 +8.51 2 na ? ? 57.6 55.556 -3.55 8 62.500 +8.51 3 62.500 +8.51 1 62.500 +8.51 0
pic16f87/88 ds30487c-page 102 ? 2005 microchip technology inc. 11.2 ausart asynchronous mode in this mode, the ausart uses standard non-return- to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip, dedicated, 8-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the ausart transmits and receives the lsb first. the transmitter and receiver are functionally independent, but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate, depending on bit brgh (txsta<2>). parity is not supported by the hardware, but can be implemented in software (and stored as the ninth data bit). asynchronous mode is stopped during sleep. asynchronous mode is selected by clearing bit sync (txsta<4>). the ausart asynchronous module consists of the following important elements:  baud rate generator  sampling circuit  asynchronous transmitter  asynchronous receiver 11.2.1 ausart asynchronous transmitter the ausart transmitter block diagram is shown in figure 11-1. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit, txif (pir1<4>), is set. this interrupt can be enabled/disabled by setting/clearing enable bit, txie (pie1<4>). flag bit txif will be set, regardless of the state of enable bit txie and cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. status bit trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data and the baud rate generator (brg) has produced a shift clock (figure 11-2). the transmission can also be started by first loading the txreg register and then setting enable bit txen. normally, when transmission is first started, the tsr register is empty. at that point, transfer to the txreg register will result in an immedi- ate transfer to tsr, resulting in an empty txreg. a back-to-back transfer is thus possible (figure 11-3). clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. as a result, the rb5/ss /tx/ck pin will revert to high-impedance. in order to select 9-bit transmission, transmit bit, tx9 (txsta<6>), should be set and the ninth bit should be written to tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg register can result in an immediate transfer of the data to the tsr register (if the tsr is empty). in such a case, an incorrect ninth data bit may be loaded in the tsr register. figure 11-1: ausart transmit block diagram note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. txif is cleared by loading txreg. txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rb5/ss /tx/ck pin pin buffer and control 8 ? ? ?
? 2005 microchip technology inc. ds30487c-page 103 pic16f87/88 when setting up an asynchronous transmission, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh ( section 11.1 ?ausart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set transmit bit tx9. 5. enable the transmission by setting bit txen which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. figure 11-2: asynchronous master transmission figure 11-3: asynchronous master transmission (back to back) table 11-7: registers associated with asynchronous transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg ausart transmit data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg brg output (shift clock) rb5/ss /tx/ck pin txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) word 1 transmit shift reg. write to txreg brg output (shift clock) rb5/ss /tx/ck pin txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows tw o consecutive transmissions.
pic16f87/88 ds30487c-page 104 ? 2005 microchip technology inc. 11.2.2 ausart asynchronous receiver the receiver block diagram is shown in figure 11-4. the data is received on the rb2/sdo/rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter, operating at x16 times the baud rate; whereas, the main receive serial shifter operates at the bit rate or at f osc . once asynchronous mode is selected, reception is enabled by setting bit cren (rcsta<4>). the heart of the receiver is the receive (serial) shift register (rsr). after sampling the stop bit, the received data in the rsr is transferred to the rcreg register (if it is empty). if the transfer is complete, flag bit, rcif (pir1<5>), is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read-only bit which is cleared by the hardware. it is cleared when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting to the rsr register. on the detection of the stop bit of the third byte, if the rcreg register is still full, the overrun error bit, oerr (rcsta<1>), will be set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. overrun bit oerr has to be cleared in soft- ware. this is done by resetting the receive logic (cren is cleared and then set). if bit oerr is set, transfers from the rsr register to the rcreg register are inhib- ited and no further data will be received. it is, therefore, essential to clear error bit oerr if it is set. framing error bit, ferr (rcsta<2>), is set if a stop bit is detected as clear. bit ferr and the 9th receive bit are buffered the same way as the receive data. reading the rcreg will load bits rx9d and ferr with new values; therefore, it is essential for the user to read the rcsta register, before reading the rcreg register, in order not to lose the old ferr and rx9d information. figure 11-4: ausart receive block diagram figure 11-5: asynchronous reception x64 baud rate clk spbrg baud rate generator rb2/sdo/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? f osc start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx pin reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word, causing the oerr (overrun) bit to be set.
? 2005 microchip technology inc. ds30487c-page 105 pic16f87/88 when setting up an asynchronous reception, follow these steps: 1. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh ( section 11.1 ?ausart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, then set enable bit rcie. 4. if 9-bit reception is desired, then set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit rcif will be set when reception is com- plete and an interrupt will be generated if enable bit rcie is set. 7. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-8: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg ausart receive data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 106 ? 2005 microchip technology inc. 11.2.3 setting up 9-bit mode with address detect when setting up an asynchronous reception with address detect enabled:  initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh.  enable the asynchronous serial port by clearing bit sync and setting bit spen.  if interrupts are desired, then set enable bit rcie.  set bit rx9 to enable 9-bit reception.  set adden to enable address detect.  enable the reception by setting enable bit cren.  flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set.  read the rcsta register to get the ninth bit and determine if any error occurred during reception.  read the 8-bit received data by reading the rcreg register to determine if the device is being addressed.  if any error occurred, clear the error by clearing enable bit cren.  if the device has been addressed, clear the adden bit to allow data bytes and address bytes to be read into the receive buffer and interrupt the cpu. figure 11-6: ausart receive block diagram x64 baud rate clk spbrg baud rate generator rb2/sdo/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? rx9 adden rx9 adden rsr<8> enable load of receive buffer 8 8 f osc
? 2005 microchip technology inc. ds30487c-page 107 pic16f87/88 figure 11-7: asynchronous reception with address detect figure 11-8: asynchronous reception with address byte first table 11-9: registers associated with asynchronous reception start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 rb2/sdo/rx/dt pin load rsr read rcif word 1 rcreg bit 8 = 0 , data byte bit 8 = 1 , address byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden = 1 . stop bit start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 rb2/sdo/rx/dt pin load rsr rcif word 1 rcreg bit 8 = 1 , address byte bit 8 = 0 , data byte note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because adden was not updated and still = 0 . read stop bit address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg ausart receive data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ?brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 108 ? 2005 microchip technology inc. 11.3 ausart synchronous master mode in synchronous master mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition, enable bit spen (rcsta<7>) is set in order to configure the rb5/ss /tx/ck and rb2/sdo/rx/dt i/o pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ck line. the master mode is entered by setting bit csrc (txsta<7>). 11.3.1 ausart synchronous master transmission the ausart transmitter block diagram is shown in figure 11-6. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cycle ), the txreg is empty and interrupt bit txif (pir1<4>) is set. the interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set, regardless of the state of enable bit txie and cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr reg- ister is empty. the tsr is not mapped in data memory, so it is not available to the user. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data. the first data bit will be shifted out on the next available rising edge of the clock on the ck line. data out is stable around the falling edge of the synchronous clock (figure 11-9). the transmission can also be started by first loading the txreg register and then setting bit txen (figure 11-10). this is advantageous when slow baud rates are selected, since the brg is kept in reset when bits txen, cren and sren are clear. setting enable bit txen will start the brg, creating a shift clock immediately. normally, when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr, resulting in an empty txreg. back-to-back transfers are possible. clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. the dt and ck pins will revert to high- impedance. if either bit cren or bit sren is set during a transmission, the transmission is aborted and the dt pin reverts to a high-impedance state (for a reception). the ck pin will remain an output if bit csrc is set (internal clock). the transmitter logic, however, is not reset, although it is disconnected from the pins. in order to reset the transmitter, the user has to clear bit txen. if bit sren is set (to interrupt an on-going transmission and receive a single word), then after the single word is received, bit sren will be cleared and the serial port will revert back to transmitting, since bit txen is still set. the dt line will immediately switch from high- impedance receive mode to transmit and start driving. to avoid this, bit txen should be cleared. in order to select 9-bit transmission, the tx9 (txsta<6>) bit should be set and the ninth bit should be written to bit tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg can result in an immediate transfer of the data to the tsr register (if the tsr is empty). if the tsr was empty and the txreg was written before writing the ?new? tx9d, the ?present? value of bit tx9d is loaded. steps to follow when setting up a synchronous master transmission: 1. initialize the spbrg register for the appropriate baud rate ( section 11.1 ?ausart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set.
? 2005 microchip technology inc. ds30487c-page 109 pic16f87/88 table 11-10: registers associated with synchronous master transmission figure 11-9: synchronous transmission figure 11-10: synchronous transmission (through txen) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg ausart transmit data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. bit 0 bit 1 bit 7 word 1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 rb2/sdo/ rb5/ss /tx/ write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode; spbrg = 0 . continuous transmission of two 8-bit words. rx/dt pin ck pin rb2/sdo/rx/dt pin rb5/ss /tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit
pic16f87/88 ds30487c-page 110 ? 2005 microchip technology inc. 11.3.2 ausart synchronous master reception once synchronous mode is selected, reception is enabled by setting either enable bit sren (rcsta<5>), or enable bit cren (rcsta<4>). data is sampled on the rb2/sdo/rx/dt pin on the falling edge of the clock. if enable bit sren is set, then only a single word is received. if enable bit cren is set, the reception is continuous until cren is cleared. if both bits are set, cren takes precedence. after clocking the last bit, the received data in the receive shift register (rsr) is transferred to the rcreg register (if it is empty). when the transfer is complete, interrupt flag bit, rcif (pir1<5>), is set. the actual interrupt can be enabled/disabled by setting/ clearing enable bit rcie (pie1<5>). flag bit rcif is a read-only bit which is reset by the hardware. in this case, it is reset when the rcreg register has been read and is empty. the rcreg is a double-buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting into the rsr register. on the clocking of the last bit of the third byte, if the rcreg register is still full, then overrun error bit, oerr (rcsta<1>), is set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. bit oerr has to be cleared in software (by clearing bit cren). if bit oerr is set, transfers from the rsr to the rcreg are inhibited, so it is essential to clear bit oerr if it is set. the ninth receive bit is buffered the same way as the receive data. reading the rcreg register will load bit rx9d with a new value, therefore, it is essential for the user to read the rcsta register, before reading rcreg, in order not to lose the old rx9d information. when setting up a synchronous master reception: 1. initialize the spbrg register for the appropriate baud rate ( section 11.1 ?ausart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, then set enable bit rcie. 5. if 9-bit reception is desired, then set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit, rcif, will be set when reception is complete and an interrupt will be generated if enable bit, rcie, was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-11: registers associated with synchronous master reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg ausart receive data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
? 2005 microchip technology inc. ds30487c-page 111 pic16f87/88 figure 11-11: synchronous reception (master mode, sren) 11.4 ausart synchronous slave mode synchronous slave mode differs from the master mode in the fact that the shift clock is supplied externally at the rb5/ss /tx/ck pin (instead of being supplied inter- nally in master mode). this allows the device to trans- fer or receive data while in sleep mode. slave mode is entered by clearing bit csrc (txsta<7>). 11.4.1 ausart synchronous slave transmit the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep and if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave transmission, follow these steps: 1. enable the synchronous slave serial port by setting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, then set enable bit txie. 4. if 9-bit transmission is desired, then set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-12: registers associated with synchronous slave transmission cren bit rb2/sdo/rx/dt rb5/ss /tx/ck write to bit sren sren bit rcif bit (interrupt) read rxreg note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brg = 0 . q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 pin pin address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 19h txreg ausart transmit data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
pic16f87/88 ds30487c-page 112 ? 2005 microchip technology inc. 11.4.2 ausart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of the sleep mode. bit sren is a ?don?t care? in slave mode. if receive is enabled by setting bit cren prior to the sleep instruction, then a word may be received during sleep. on completely receiving the word, the rsr reg- ister will transfer the data to the rcreg register and if enable bit rcie bit is set, the interrupt generated will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). when setting up a synchronous slave reception, follow these steps: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 6. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that gie and peie (bits 7 and 6) of the intcon register are set. table 11-13: registers associated with synchronous slave reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ? adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg ausart receive data register 0000 0000 0000 0000 8ch pie1 ? adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 98h txsta csrc tx9 txen sync ? brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87.
? 2005 microchip technology inc. ds30487c-page 113 pic16f87/88 12.0 analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has seven inputs for 18/20 pin devices (pic16f88 devices only). the conversion of an analog input signal results in a corresponding 10-bit digital number. the a/d module has a high and low-voltage reference input that is software selectable to some combination of v dd , v ss , v ref - (ra2) or v ref + (ra3). the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to oper- ate in sleep, the a/d conversion clock must be derived from the a/d?s internal rc oscillator. the a/d module has five registers:  a/d result high register (adresh)  a/d result low register (adresl)  a/d control register 0 (adcon0)  a/d control register 1 (adcon1)  analog select register (ansel) the adcon0 register, shown in register 12-2, controls the operation of the a/d module. the ansel register, shown in register 12-1 and the adcon1 register, shown in register 12-3, configure the func- tions of the port pins. the port pins can be configured as analog inputs (ra3/ra2 can also be voltage references) or as digital i/o. additional information on using the a/d module can be found in the ? picmicro ? mid-range mcu family reference manual? (ds33023). register 12-1: ansel: analog select register (address 9bh) pic16f88 devices only u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? ans6 ans5 ans4 ans3 ans2 ans1 ans0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-0 ans<6:0>: analog input select bits bits select input function on corresponding an<6:0> pins. 1 = analog i/o (1,2) 0 = digital i/o note 1: setting a pin to an analog input disables the digital input buffer. the corresponding tris bit should be set to input mode when using pins as analog inputs. only an2 is an analog i/o, all other anx pins are analog inputs. 2: see the block diagrams for the analog i/o pins to see how ansel interacts with the chs bits of the adcon0 register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 114 ? 2005 microchip technology inc. register 12-2: adcon0: a/d control register (address 1fh) pic16f88 devices only r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon bit 7 bit 0 bit 7-6 adcs<1:0>: a/d conversion clock select bits if ad c s 2 = 0 : 00 = f osc /2 01 = f osc /8 10 = f osc /32 11 = f rc (clock derived from the internal a/d module rc oscillator) if ad c s 2 = 1 : 00 = f osc /4 01 = f osc /16 10 = f osc /64 11 = f rc (clock derived from the internal a/d module rc oscillator) bit 5-3 chs<2:0>: analog channel select bits 000 = channel 0 (ra0/an0) 001 = channel 1 (ra1/an1) 010 = channel 2 (ra2/an2) 011 = channel 3 (ra3/an3) 100 = channel 4 (ra4/an4) 101 = channel 5 (rb6/an5) 110 = channel 6 (rb7/an6) bit 2 go/done : a/d conversion status bit if adon = 1 : 1 = a/d conversion in progress (setting this bit starts the a/d conversion) 0 = a/d conversion not in progress (this bit is automatically cleared by hardware when the a/d conversion is complete) bit 1 unimplemented: read as ? 0 ? bit 0 adon: a/d on bit 1 = a/d converter module is operating 0 = a/d converter module is shut off and consumes no operating current legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 115 pic16f87/88 register 12-3: adcon1: a/d control register 1 (address 9fh) pic16f88 devices only r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 adfm adcs2 vcfg1 vcfg0 ? ? ? ? bit 7 bit 0 bit 7 adfm: a/d result format select bit 1 = right justified. six most significant bits of adresh are read as ? 0 ?. 0 = left justified. six least significant bits of adresl are read as ? 0 ?. bit 6 adcs2: a/d clock divide by 2 select bit 1 = a/d clock source is divided by 2 when system clock is used 0 =disabled bit 5-4 vcfg<1:0>: a/d voltage reference configuration bits note: the ansel bits for an3 and an2 inputs must be configured as analog inputs for the v ref + and v ref - external pins to be used. bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown logic state v ref +v ref - 00 av dd av ss 01 av dd v ref- 10 v ref+ av ss 11 v ref+ v ref-
pic16f87/88 ds30487c-page 116 ? 2005 microchip technology inc. the adresh:adresl registers contain the result of the a/d conversion. when the a/d conversion is complete, the result is loaded into the a/d result register pair, the go/done bit (adcon0<2>) is cleared and a/d interrupt flag bit, adif, is set. the block diagram of the a/d module is shown in figure 12-1. after the a/d module has been configured as desired, the selected channel must be acquired before the conversion is started. the analog input channels must have their corresponding tris bits selected as inputs. to determine sample time, see section 12.1 ?a/d acquisition requirements? . after this sample time has elapsed, the a/d conversion can be started. these steps should be followed for doing an a/d conversion: 1. configure the a/d module:  configure analog/digital i/o (ansel)  configure voltage reference (adcon1)  select a/d input channel (adcon0)  select a/d conversion clock (adcon0)  turn on a/d module (adcon0) 2. configure a/d interrupt (if desired):  clear adif bit  set adie bit  set peie bit  set gie bit 3. wait the required acquisition time. 4. start conversion:  set go/done bit (adcon0) 5. wait for a/d conversion to complete, by either:  polling for the go/done bit to be cleared (with interrupts disabled); or  waiting for the a/d interrupt 6. read a/d result register pair (adresh:adresl), clear bit adif if required. 7. for next conversion, go to step 1 or step 2 as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before the next acquisition starts. figure 12-1: a/d block diagram (input voltage) v in v ref + (reference voltage) av dd vcfg1:vcfg0 chs2:chs0 ra3/an3/v ref +/c1out ra2/an2/cv ref /v ref - ra1/an1 ra0/an0 011 010 001 000 a/d converter v ref - (reference voltage) av ss vcfg1:vcfg0 rb6/an5/pgc/t1oso/t1cki rb7/an6/pgd/t1osi ra4/an4/t0cki/c2out 110 101 100
? 2005 microchip technology inc. ds30487c-page 117 pic16f87/88 12.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the ana- log input model is shown in figure 12-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), see figure 12-2. the maximum recommended impedance for analog sources is 10 k ? . as the impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (changed), this acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 12-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. to calculate the minimum acquisition time, t acq , see the ? picmicro ? mid-range mcu family reference manual? (ds33023). equation 12-1: acquisition time figure 12-2: analog input model t acq t c t acq = = = = = = = = amplifier settling time + hold capacitor charging time + temperature coefficient t amp + t c + t coff 2 s + t c + [(temperature -25 c)(0.05 s/c)] c hold (r ic + r ss + r s ) in(1/2047) -120 pf (1 k ? + 7 k ? + 10 k ? ) in(0.0004885) 16.47 s 2 s + 16.47 s + [(50c ? 25 c)(0.05 s/ c) 19.72 s note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k ? . this is required to meet the pin leakage specification. 4: after a conversion has completed, a 2.0 t ad delay must complete before acquisition can begin again. during this time, the holding capacitor is not connected to the selected a/d input channel. c pin va r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = dac capacitance v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ? ) v dd = 120 pf 500 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions
pic16f87/88 ds30487c-page 118 ? 2005 microchip technology inc. 12.2 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 9.0 t ad per 10-bit conversion. the source of the a/d conversion clock is software selectable. the seven possible options for t ad are: 2t osc 4t osc 8t osc 16t osc 32t osc 64t osc  internal a/d module rc oscillator (2-6 s) for correct a/d conversions, the a/d conversion clock (t ad ) must be selected to ensure a minimum t ad time as small as possible, but no less than 1.6 s and not greater than 6.4 s. table 12-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. 12.3 operation in power-managed modes the selection of the automatic acquisition time and a/d conversion clock is determined in part by the clock source and frequency while in a power-managed mode. if the a/d is expected to operate while the device is in a power-managed mode, the adcs2:adcs0 bits in adcon0 and adcon1 should be updated in accor- dance with the power-managed mode clock that will be used. after the power-managed mode is entered (either of the power-managed run modes), an a/d acquisition or conversion may be started. once an acquisition or conversion is started, the device should continue to be clocked by the same power-managed mode clock source until the conversion has been completed. if the power-managed mode clock frequency is less than 1 mhz, the a/d rc clock source should be selected. table 12-1: t ad vs. maximum device operating frequencies ? standard devices (c) ad clock source (t ad ) maximum device frequency operation adcs<2> adcs<1:0> max. 2 t osc 000 1.25 mhz 4 t osc 100 2.5 mhz 8 t osc 001 5 mhz 16 t osc 101 10 mhz 32 t osc 010 20 mhz 64 t osc 110 20 mhz rc (1,2,3) x11 (note 1) note 1: the rc source has a typical t ad time of 4 s, but can vary between 2-6 s. 2: when the device frequencies are greater than 1 mhz, the rc a/d conversion clock source is only recommended for sleep operation. 3: for extended voltage devices (lf), please refer to section 18.0 ?electrical characteristics? .
? 2005 microchip technology inc. ds30487c-page 119 pic16f87/88 12.4 configuring analog port pins the adcon1, ansel, trisa and trisb registers control the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs<2:0> bits and the tris bits. 12.5 a/d conversions clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. that is, the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is aborted, a 2 t ad wait is required before the next acquisition is started. after this 2 t ad wait, acquisition on the selected channel is automatically started. the go/done bit can then be set to start the conversion. in figure 12-3, after the go/done bit is set, the first time segment has a minimum of t cy and a maximum of t ad . 12.5.1 a/d result registers the adresh:adresl register pair is the location where the 10-bit a/d result is loaded at the completion of the a/d conversion. this register pair is 16 bits wide. the a/d module gives the flexibility to left or right justify the 10-bit result in the 16-bit result register. the a/d format select bit (adfm) controls this justification. figure 12-4 shows the operation of the a/d result justification. the extra bits are loaded with ? 0 ?s. when an a/d result will not overwrite these locations (a/d disable), these registers may be used as two general purpose 8-bit registers. figure 12-3: a/d conversion t ad cycles figure 12-4: a/d result justification note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins config- ured as digital inputs will convert an analog input. analog levels on a digitally configured input will not affect the conversion accuracy. 2: analog levels on any pin that is defined as a digital input (including the ra4:ra0 and rb7:rb6 pins), may cause the input buffer to consume current out of the device specification. note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go/done bit holding capacitor is disconnected fr om analog input (typically 100 ns) b9 b8 b7 b6 b5 b4 b3 b2 t ad 10 t ad 11 b1 b0 t cy to t ad conversion starts adres is loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input 10-bit result adresh adresl 0000 00 adfm = 0 0 2 1 0 7 7 10-bit result adresh adresl 10-bit result 0000 00 7 0 7 6 5 0 adfm = 1 right justified left justified
pic16f87/88 ds30487c-page 120 ? 2005 microchip technology inc. 12.6 a/d operation during sleep the a/d module can operate during sleep mode. this requires that the a/d clock source be set to rc (adcs1:adcs0 = 11 ). when the rc clock source is selected, the a/d module waits one instruction cycle before starting the conversion. this allows the sleep instruction to be executed which eliminates all digital switching noise from the conversion. when the conver- sion is completed, the go/done bit will be cleared and the result loaded into the adres registers. if the a/d interrupt is enabled, the device will wake-up from sleep. if the a/d interrupt is not enabled, the a/d module will then be turned off, although the adon bit will remain set. when the a/d clock source is another clock option (not rc), a sleep instruction will cause the present conver- sion to be aborted and the a/d module to be turned off, though the adon bit will remain set. turning off the a/d places the a/d module in its lowest current consumption state. 12.7 effects of a reset a device reset forces all registers to their reset state. the a/d module is disabled and any conversion in progress is aborted. all a/ d input pins are configured as analog inputs. the value that is in the adresh:adresl registers is not modified for a power-on reset. the adresh:adresl registers will contain unknown data after a power-on reset. 12.8 use of the ccp trigger an a/d conversion can be started by the ?special event trigger? of the ccp module. this requires that the ccp1m3:ccp1m0 bits (ccp1con<3:0>) be pro- grammed as ? 1011 ? and that the a/d module is enabled (adon bit is set). when the trigger occurs, the go/ done bit will be set, starting the a/d conversion and the timer1 counter will be reset to zero. timer1 is reset to automatically repeat the a/d acquisition period with minimal software overhead (moving the adresh:adresl to the desired location). the appro- priate analog input channel must be selected and the minimum acquisition done before the ?special event trigger? sets the go/done bit (starts a conversion). if the a/d module is not enabled (adon is cleared), then the ?special event trigger? will be ignored by the a/d module, but will still reset the timer1 counter. note: for the a/d module to operate in sleep, the a/d clock source must be set to rc (adcs1:adcs0 = 11 ). to perform an a/d conversion in sleep, ensure the sleep instruction immediately follows the instruction that sets the go/done bit. table 12-2: registers/bits associated with a/d address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets 0bh, 8bh 10bh, 18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0ch pir1 ?adif (1) rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 8ch pie1 ?adie (1) rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 1eh adresh (2) a/d result register high byte xxxx xxxx uuuu uuuu 9eh adresl (2) a/d result register low byte xxxx xxxx uuuu uuuu 1fh adcon0 (2) adcs1 adcs0 chs2 chs1 chs0 go/done ?adon 0000 00-0 0000 00-0 9fh adcon1 (2) adfm adcs2 vcfg1 vcfg0 ? ? ? ? 0000 ---- 0000 ---- 9bh ansel (2 ? ans6 ans5 ans4 ans3 ans2 ans1 ans0 -111 1111 -111 1111 05h porta (pic16f87) (pic16f88) ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx 0000 xxx0 0000 uuuu 0000 uuu0 0000 05h, 106h portb (pic16f87) (pic16f88) rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 00xx xxxx uuuu uuuu 00uu uuuu 85h trisa trisa7 trisa6 trisa5 (3) porta data direction register (trisa<4:0>) 1111 1111 1111 1111 86h, 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used for a/d conversion. note 1: this bit is only implemented on the pic16f88. the bit will read ? 0 ? on the pic16f87. 2: pic16f88 only. 3: pin 5 is an input only; the state of the tr isa5 bit has no effect and will always read ? 1 ?.
? 2005 microchip technology inc. ds30487c-page 121 pic16f87/88 13.0 comparator module the comparator module contains two analog comparators. the inputs to the comparators are multiplexed with i/o port pins ra0 through ra3, while the outputs are multiplexed to pins ra3 and ra4. the on-chip voltage reference ( section 14.0 ?comparator voltage reference module? ) can also be an input to the comparators. the cmcon register (register 13-1) controls the comparator input and output multiplexors. a block diagram of the various comparator configurations is shown in figure 13-1. register 13-1: cmcon: comparator module control regist er (address 9ch) r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out: comparator 2 output bit when c2inv = 0 : 1 = c2 v in + > c2 v in - 0 = c2 v in + < c2 v in - when c2inv = 1 : 1 = c2 v in + < c2 v in - 0 = c2 v in + > c2 v in - bit 6 c1out: comparator 1 output bit when c1inv = 0 : 1 = c1 v in + > c1 v in - 0 = c1 v in + < c1 v in - when c1inv = 1 : 1 = c1 v in + < c1 v in - 0 = c1 v in + > c1 v in - bit 5 c2inv: comparator 2 output inversion bit 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv: comparator 1 output inversion bit 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis: comparator input switch bit when cm2:cm0 = 001 : 1 =c1 v in - connects to ra3 0 =c1 v in - connects to ra0 when cm2:cm0 = 010 : 1 =c1 v in - connects to ra3 c2 v in - connects to ra2 0 =c1 v in - connects to ra0 c2 v in - connects to ra1 bit 2-0 cm<2:0>: comparator mode bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 122 ? 2005 microchip technology inc. 13.1 comparator configuration there are eight modes of operation for the compara- tors. the cmcon register is used to select these modes. figure 13-1 shows the eight possible modes. the trisa register controls the data direction of the comparator pins for each mode. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in section 18.0 ?electrical characteristics? . figure 13-1: comparator i/o operating modes note: comparator interrupts should be disabled during a comparator mode change; otherwise, a false interrupt may occur. c1 ra0/an0 v in - v in + ra3/an3/ off (read as ? 0 ?) comparators reset a a cm2:cm0 = 000 c2 ra1/an1 v in - v in + ra2/an2/ off (read as ? 0 ?) a a c1 ra0/an0 v in - v in + ra3/an3/ c1out two independent comparators a a cm2:cm0 = 100 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a c1 ra0/an0 v in - v in + ra3/an3/ c1out two common reference comparators a d cm2:cm0 = 011 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a c1 ra0/an0 v in - v in + ra3/an3/ off (read as ? 0 ?) one independent comparator d d cm2:cm0 = 101 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a c1 ra0/an0 v in - v in + ra3/an3/ off (read as ? 0 ?) comparators off (por default value) d d cm2:cm0 = 111 c2 ra1/an1 v in - v in + ra2/an2/ off (read as ? 0 ?) d d c1 ra0/an0 v in - v in + ra3/an3/ c1out four inputs multiplexed to two comparators a a cm2:cm0 = 010 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a from v ref module cis = 0 cis = 1 cis = 0 cis = 1 c1 ra0/an0 v in - v in + ra3/an3/ c1out two common reference comparators with outputs a d cm2:cm0 = 110 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a a = analog input, port reads zeros always. d = digital input. cis (cmcon<3>) is the comparator input switch. ra4/t0cki/c2out c1 ra0/an0 v in - v in + ra3/an3/ c1out three inputs multiplexed to two comparators a a cm2:cm0 = 001 c2 ra1/an1 v in - v in + ra2/an2/ c2out a a cis = 0 cis = 1 c1out c1out c1out c1out c1out c1out c1out c1out cv ref cv ref cv ref cv ref cv ref cv ref cv ref cv ref
? 2005 microchip technology inc. ds30487c-page 123 pic16f87/88 13.2 comparator operation a single comparator is shown in figure 13-2, along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 13-2 represent the uncertainty due to input offsets and response time. 13.3 comparator reference an external or internal reference signal may be used depending on the comparator operating mode. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly (figure 13-2). figure 13-2: single comparator 13.3.1 external reference signal when external voltage references are used, the comparator module can be configured to have the com- parators operate from the same, or different reference sources. however, threshold detector applications may require the same reference. the reference signal must be between v ss and v dd and can be applied to either pin of the comparator(s). 13.3.2 internal reference signal the comparator module also allows the selection of an internally generated voltage reference for the comparators. section 14.0 ?comparator voltage reference module? contains a detailed description of the comparator voltage reference module that provides this signal. the internal reference signal is used when comparators are in mode cm<2:0> = 010 (figure 13-1). in this mode, the internal voltage reference is applied to the v in + pin of both comparators. 13.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. if the internal reference is changed, the maximum delay of the inter- nal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used ( section 18.0 ?electrical characteristics? ). 13.5 comparator outputs the comparator outputs are read through the cmcon register. these bits are read-only. the comparator outputs may also be directly output to the ra3 and ra4 i/o pins. when enabled, multiplexors in the output path of the ra3 and ra4 pins will switch and the output of each pin will be the unsynchronized output of the com- parator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 13-3 shows the comparator output block diagram. the trisa bits will still function as an output enable/ disable for the ra3 and ra4 pins while in this mode. the polarity of the comparator outputs can be changed using the c2inv and c1inv bits (cmcon<5:4>). ? + v in + v in - output v in? v in+ o utput output v in + v in - note 1: when reading the port register, all pins configured as analog inputs will read as ? 0 ?. pins configured as digital inputs will convert an analog input, according to the schmitt trigger input specification. 2: analog levels, on any pin defined as a digital input, may cause the input buffer to consume more current than is specified.
pic16f87/88 ds30487c-page 124 ? 2005 microchip technology inc. figure 13-3: comparator output block diagram 13.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:6>, to determine the actual change that occurred. the cmif bit (pir2 register) is the comparator interrupt flag. the cmif bit must be reset by clearing it (? 0 ?). since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. the cmie bit (pie2 register) and the peie bit (intcon register) must be set to enable the interrupt. in addition, the gie bit must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of cmcon will end the mismatch condition. b) clear flag bit cmif. a mismatch condition will continue to set flag bit cmif. reading cmcon will end the mismatch condition and allow flag bit cmif to be cleared. d q en rd_cmcon set cmif bit multiplex d q en cl port pins q3 * rd_cmcon r eset from other comparator to data bus q1 cninv note: if a change in the cmcon register (c1out or c2out) should occur when a read operation is being executed (start of the q2 cycle), then the cmif (pir2 register) interrupt flag may not get set.
? 2005 microchip technology inc. ds30487c-page 125 pic16f87/88 13.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional, if enabled. this interrupt will wake-up the device from sleep mode when enabled. while the comparator is powered up, higher sleep currents than shown in the power-down current specification will occur. each operational comparator will consume additional current, as shown in the com- parator specifications. to minimize power consumption while in sleep mode, turn off the comparators, cm<2:0> = 111 , before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 13.8 effects of a reset a device reset forces the cmcon register to its reset state, causing the comparator module to be in the comparator off mode, cm<2:0> = 111 . 13.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 13-4. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 13-4: analog input model va r s < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 500 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage
pic16f87/88 ds30487c-page 126 ? 2005 microchip technology inc. table 13-1: registers associated with the comparator module address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 9ch cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0111 0000 0111 9dh cvrcon cvren cvroe cvrr ? cvr3 cvr2 cvr1 cvr0 000- 0000 000- 0000 0bh, 8bh, 10bh, 18bh intcon gie peie tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 0000 000u 0dh pir2 osfif cmif ? eeif ? ? ? ? 00-0 ---- 00-0 ---- 8dh pie2 osfie cmie ? eeie ? ? ? ? 00-0 ---- 00-0 ---- 05h porta (pic16f87) (pic16f88) ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx 0000 xxx0 0000 uuuu 0000 uuu0 0000 85h trisa trisa7 trisa6 trisa5 (1) trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used by the comparator module. note 1: pin 5 is an input only; the state of the tr isa5 bit has no effect and will always read ? 1 ?.
? 2005 microchip technology inc. ds30487c-page 127 pic16f87/88 14.0 comparator voltage reference module the comparator voltage refe rence generator is a 16-tap resistor ladder network that provides a fixed voltage reference when the comparators are in mode ? 010 ?. a programmable register controls the function of the refer- ence generator. register 14-1 lists the bit functions of the cvrcon register. as shown in figure 14-1, the resistor ladder is seg- mented to provide two ranges of cv ref values and has a power-down function to conserve power when the reference is not being used. the comparator reference supply voltage (also referred to as cv rsrc ) comes directly from v dd . it should be noted, however, that the voltage at the top of the ladder is cv rsrc ? v sat , where v sat is the saturation voltage of the power switch transistor. this reference will only be as accurate as the values of cv rsrc and v sat . the output of the reference generator may be connected to the ra2/an2/cv ref /v ref - pin (v ref - is available on the pic16f88 device only). this can be used as a simple d/a function by the user if a very high- impedance load is used. the primary purpose of this function is to provide a test path for testing the reference generator function. register 14-1: cvrcon: comparator vo ltage reference control register (address 9dh) r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrr ? cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 bit 7 cvren: comparator voltage reference enable bit 1 = cv ref circuit powered on 0 = cv ref circuit powered down bit 6 cvroe: comparator v ref output enable bit 1 = cv ref voltage level is output on the ra2/an2/cv ref /v ref - pin (1) 0 = cv ref voltage level is disconnected from the ra2/an2/cv ref /v ref - pin (1) bit 5 cvrr: comparator v ref range selection bit (1) 1 = 0.00 cv rsrc to 0.625 cv rsrc with cv rsrc /24 step size 0 = 0.25 cv rsrc to 0.72 cv rsrc with cv rsrc /32 step size bit 4 unimplemented: read as ? 0 ? bit 3-0 cvr<3:0>: comparator v ref value selection 0 vr3:vr0 15 bits (1) when cvrr = 1 : cv ref = (vr<3:0>/24) ? (cv rsrc ) when cvrr = 0 : cv ref = 1/4 ? (cv rsrc ) + (vr3:vr0/32) ? (cv rsrc ) note 1: v ref is available on the pic16f88 device only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 128 ? 2005 microchip technology inc. figure 14-1: comparator voltage reference block diagram table 14-1: registers associated with comparator voltage reference cvrr 8r cvr3 cvr0 16-to-1 analog mux 8r r r r r cvren cv ref 16 stages input to comparator cvroe ra2/an2/cv ref /v ref - pin (1) v dd cvr2 cvr1 note 1: v ref is available on the pic16f88 device only. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 9dh cvrcon cvren cvroe cvrr ? cvr3 cvr2 cvr1 cvr0 000- 0000 000- 0000 9ch cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0111 0000 0111 legend: x = unknown, u = unchanged, - = unimplemented, read as ? 0 ?. shaded cells are not used with the comparator voltage reference.
? 2005 microchip technology inc. ds30487c-page 129 pic16f87/88 15.0 special features of the cpu these devices have a host of features intended to max- imize system reliability, minimize cost through elimina- tion of external components, provide power-saving operating modes and offer code protection:  reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor)  interrupts  watchdog timer (wdt)  two-speed start-up  fail-safe clock monitor  sleep  code protection  id locations  in-circuit serial programming? (icsp?) there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 72 ms (nomi- nal) on power-up only. it is designed to keep the part in reset while the power supply stabilizes and is enabled or disabled using a configuration bit. with these two timers on-chip, most applications need no external reset circuitry. sleep mode is designed to offer a very low-current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up or through an interrupt. additional information on special features is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023). 15.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?), to select various device configurations. these bits are mapped in program memory locations 2007h and 2008h. the user will note that address 2007h is beyond the user program memory space which can be accessed only during programming.
pic16f87/88 ds30487c-page 130 ? 2005 microchip technology inc. register 15-1: config1: configuration word 1 register (addr ess 2007h) r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 cp ccpmx debug wrt1 wrt0 cpd lvp boren mclre fosc2 pwrten wdten fosc1 fosc0 bit 13 bit 0 bit 13 cp: flash program memory code protection bits 1 = code protection off 0 = 0000h to 0fffh code-protected (all protected) bit 12 ccpmx: ccp1 pin selection bit 1 = ccp1 function on rb0 0 = ccp1 function on rb3 bit 11 debug: in-circuit debugger mode bit 1 = in-circuit debugger disabled, rb6 and rb7 are general purpose i/o pins 0 = in-circuit debugger enabled, rb6 and rb7 are dedicated to the debugger bit 10-9 wrt<1:0>: flash program memory write enable bits 11 = write protection off 10 = 0000h to 00ffh write-protected, 0100h to 0fffh may be modified by eecon control 01 = 0000h to 07ffh write-protected, 0800h to 0fffh may be modified by eecon control 00 = 0000h to 0fffh write-protected bit 8 cpd: data ee memory code protection bit 1 = code protection off 0 = data ee memory code-protected bit 7 lvp: low-voltage programming enable bit 1 = rb3/pgm pin has pgm function, low-voltage programming enabled 0 = rb3 is digital i/o, hv on mclr must be used for programming bit 6 boren: brown-out reset enable bit 1 = bor enabled 0 = bor disabled bit 5 mclre: ra5/mclr /v pp pin function select bit 1 = ra5/mclr /v pp pin function is mclr 0 = ra5/mclr /v pp pin function is digital i/o, mclr internally tied to v dd bit 3 pwrten : power-up timer enable bit 1 = pwrt disabled 0 = pwrt enabled bit 2 wdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled bit 4, 1-0 fosc<2:0>: oscillator selection bits 111 = extrc oscillator; clko function on ra6/osc2/clko 110 = extrc oscillator; port i/o function on ra6/osc2/clko 101 = intrc oscillator; clko function on ra6/osc2/clko pin and port i/o function on ra7/osc1/clki pin 100 = intrc oscillator; port i/o function on both ra6/osc2/clko pin and ra7/osc1/clki pin 011 = ecio; port i/o function on ra6/osc2/clko 010 = hs oscillator 001 = xt oscillator 000 = lp oscillator legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2005 microchip technology inc. ds30487c-page 131 pic16f87/88 register 15-2: config2: configuration word 2 register (addr ess 2008h) u-1 u-1 u-1 u-1 u-1 u-1 u-1 u-1 u-1 u-1 u-1 u-1 r/p-1 r/p-1 ? ? ? ? ? ? ? ? ? ? ? ? ieso fcmen bit 13 bit 0 bit 13-2 unimplemented: read as ? 1 ? bit 1 ieso: internal external switchover bit 1 = internal external switchover mode enabled 0 = internal external switchover mode disabled bit 0 fcmen: fail-safe clock monitor enable bit 1 = fail-safe clock monitor enabled 0 = fail-safe clock monitor disabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f87/88 ds30487c-page 132 ? 2005 microchip technology inc. 15.2 reset the pic16f87/88 differentiates between various kinds of reset:  power-on reset (por) mclr reset during normal operation mclr reset during sleep  wdt reset during normal operation  wdt wake-up during sleep  brown-out reset (bor) some registers are not affected in any reset condition. their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on power-on reset (por), on the mclr and wdt reset, on mclr reset during sleep and brown- out reset (bor). they are not affected by a wdt wake-up which is viewed as the resumption of normal operation. the to and pd bits are set or cleared differently in different reset situations, as indicated in table 15-3. these bits are used in software to deter- mine the nature of the reset. upon a por, bor or wake-up from sleep, the cpu requires approximately 5-10 s to become ready for code execution. this delay runs in parallel with any other timers. see table 15-4 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 15-1. figure 15-1: simplified block diagram of on-chip reset circuit s r q external reset mclr v dd osc1 wdt module v dd rise detect ost/pwrt intrc wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 11-bit ripple counter reset enable ost enable pwrt sleep brown-out reset boren 31.25 khz
? 2005 microchip technology inc. ds30487c-page 133 pic16f87/88 15.3 mclr pic16f87/88 devices have a noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a wdt reset does not drive mclr pin low. the behavior of the esd protection on the mclr pin has been altered from previous devices of this family. voltages applied to the pin that exceed its specification can result in both mclr and excessive current beyond the device specification during the esd event. the circuit, as shown in figure 15-2, is suggested. the ra5/mclr /v pp pin can be configured for mclr (default), or as an i/o pin (ra5). this is configured through the mclre bit in configuration word 1. figure 15-2: external power-on reset circuit (for slow v dd power-up) 15.4 power-on reset (por) a power-on reset pulse is generated on-chip when v dd rise is detected (in the range of 1.2v-1.7v). to take advantage of the por, tie the mclr pin to v dd , as described in section 15.3 ?mclr ? . a maximum rise time for v dd is specified. see section 18.0 ?electrical characteristics? for details. when the device starts normal operation (exits the reset condition), device operating parameters (volt- age, frequency, temperature,...) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. for more information, see application note, an607 ?power-up trouble shooting? (ds00607). 15.5 power-up timer (pwrt) the power-up timer (pwrt) of the pic16f87/88 is a counter that uses the intrc oscillator as the clock input. this yields a count of 72 ms. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intrc and will vary from chip-to-chip due to temperature and process variation. see dc parameter #33 for details. the pwrt is enabled by clearing configuration bit pwrten . 15.6 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over (if enabled). this helps to ensure that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp and hs modes and only on power-on reset or wake-up from sleep. 15.7 brown-out reset (bor) the configuration bit, boren, can enable or disable the brown-out reset circuit. if v dd falls below v bor (parameter d005, about 4v) for longer than t bor (parameter #35, about 100 s), the brown-out situation will reset the device. if v dd falls below v bor for less than t bor , a reset may not occur. once the brown-out occurs, the device will remain in brown-out reset until v dd rises above v bor . the power-up timer (if enabled) will keep the device in reset for t pwrt (parameter #33, about 72 ms). if v dd should fall below v bor during t pwrt , the brown-out reset process will restart when v dd rises above v bor with the power-up timer reset. unlike previous pic16 devices, the pwrt is no longer automatically enabled when the brown-out reset circuit is enabled. the pwrten and boren configuration bits are independent of each other. note: for this reason, microchip recommends that the mclr pin no longer be tied directly to v dd . note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow. the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure that the voltage drop across r does not violate the device?s electrical specification. 3: r1 = 1 k ? to 10 k ? will limit any current flow- ing into mclr from external capacitor c (0.1 f), in the event of ra5/m clr/ v pp pin breakdown due to electrostatic discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic16f87/88
pic16f87/88 ds30487c-page 134 ? 2005 microchip technology inc. 15.8 time-out sequence on power-up, the time-out sequence is as follows: the pwrt delay starts (if enabled) when a por occurs. then, ost starts counting 1024 oscillator cycles when pwrt ends (lp, xt, hs). when the ost ends, the device comes out of reset. if mclr is kept low long enough, all delays will expire. bringing mclr high will begin execution immediately. this is useful for testing purposes, or to synchronize more than one pic16f87/88 device operating in parallel. table 15-3 shows the reset conditions for the status, pcon and pc registers, while table 15-4 shows the reset conditions for all the registers. 15.9 power control/status register (pcon) the power control/status register, pcon, has two bits to indicate the type of reset that last occurred. bit 0 is brown-out reset status bit, bor . bit bor is unknown on a power-on reset. it must then be set by the user and checked on subsequent resets to see if bit bor cleared, indicating a brown-out reset occurred. when the brown-out reset is disabled, the state of the bor bit is unpredictable. bit 1 is por (power-on reset status bit). it is cleared on a power-on reset and unaffected otherwise. the user must set this bit following a power-on reset. table 15-1: time-out in various situations table 15-2: status bits and their significance oscillator configuration power-up brown-out reset wake-up from sleep pwrte = 0 pwrte = 1 pwrte = 0 pwrte = 1 xt, hs, lp t pwrt + 1024  t osc 1024  t osc t pwrt + 1024  t osc 1024  t osc 1024  t osc extrc, intrc t pwrt 5-10 s (1) t pwrt 5-10 s (1) 5-10 s (1) t1osc ? ???5-10 s (1) note 1: cpu start-up is always invoked on por, bor and wake-up from sleep. the 5-10 s delay is based on a 1 mhz system clock. por bor to pd 0x11 power-on reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 1011 brown-out reset 1101 wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep or interrupt wake-up from sleep legend: u = unchanged, x = unknown
? 2005 microchip technology inc. ds30487c-page 135 pic16f87/88 table 15-3: reset condition for special registers condition program counter status register pcon register power-on reset 000h 0001 1xxx ---- --0x mclr reset during normal operation 000h 000u uuuu ---- --uu mclr reset during sleep 000h 0001 0uuu ---- --uu wdt reset 000h 0000 1uuu ---- --uu wdt wake-up pc + 1 uuu0 0uuu ---- --uu brown-out reset 000h 0001 1uuu ---- --u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- --uu legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ? note 1: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). table 15-4: initialization conditions for all registers register power-on reset, brown-out reset mclr reset, wdt reset wake-up via wdt or interrupt w xxxx xxxx uuuu uuuu uuuu uuuu indf n/a n/a n/a tmr0 xxxx xxxx uuuu uuuu uuuu uuuu pcl 0000h 0000h pc + 1 (2) status 0001 1xxx 000q quuu (3) uuuq quuu (3) fsr xxxx xxxx uuuu uuuu uuuu uuuu porta (pic16f87) porta (pic16f88) xxxx 0000 xxx0 0000 uuuu 0000 uuu0 0000 uuuu uuuu uuuu uuuu portb (pic16f87) portb (pic16f87) xxxx xxxx 00xx xxxx uuuu uuuu 00uu uuuu uuuu uuuu uuuu uuuu pclath ---0 0000 ---0 0000 ---u uuuu intcon 0000 000x 0000 000u uuuu uuuu (1) pir1 -000 0000 -000 0000 -uuu uuuu (1) pir2 00-0 ---- 00-0 ---- uu-u ---- (1) tmr1l xxxx xxxx uuuu uuuu uuuu uuuu tmr1h xxxx xxxx uuuu uuuu uuuu uuuu t1con -000 0000 -uuu uuuu -uuu uuuu tmr2 0000 0000 0000 0000 uuuu uuuu t2con -000 0000 -000 0000 -uuu uuuu sspbuf xxxx xxxx uuuu uuuu uuuu uuuu sspcon 0000 0000 0000 0000 uuuu uuuu ccpr1l xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h xxxx xxxx uuuu uuuu uuuu uuuu ccp1con --00 0000 --00 0000 --uu uuuu rcsta 0000 000x 0000 000x uuuu uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in intcon, pir1 and pr2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 15-3 for reset value for specific condition.
pic16f87/88 ds30487c-page 136 ? 2005 microchip technology inc. txreg 0000 0000 0000 0000 uuuu uuuu rcreg 0000 0000 0000 0000 uuuu uuuu adresh xxxx xxxx uuuu uuuu uuuu uuuu adcon0 0000 00-0 0000 00-0 uuuu uu-u option_reg 1111 1111 1111 1111 uuuu uuuu trisa 1111 1111 1111 1111 uuuu uuuu trisb 1111 1111 1111 1111 uuuu uuuu pie1 -000 0000 -000 0000 -uuu uuuu pie2 00-0 ---- 00-0 ---- uu-u ---- pcon ---- --0q ---- --uu ---- --uu osccon -000 0000 -000 0000 -uuu uuuu osctune --00 0000 --00 0000 --uu uuuu pr2 1111 1111 1111 1111 1111 1111 sspadd 0000 0000 0000 0000 uuuu uuuu sspstat 0000 0000 0000 0000 uuuu uuuu txsta 0000 -010 0000 -010 uuuu -u1u spbrg 0000 0000 0000 0000 uuuu uuuu ansel -111 1111 -111 1111 -111 1111 cmcon 0000 0111 0000 0111 uuuu u111 cvrcon 000- 0000 000- 0000 uuu- uuuu wdtcon ---0 1000 ---0 1000 ---u uuuu adresl xxxx xxxx uuuu uuuu uuuu uuuu adcon1 0000 ---- 0000 ---- uuuu ---- eedata xxxx xxxx uuuu uuuu uuuu uuuu eeadr xxxx xxxx uuuu uuuu uuuu uuuu eedath --xx xxxx --uu uuuu --uu uuuu eeadrh ---- -xxx ---- -uuu ---- -uuu eecon1 x--x x000 u--x u000 u--u uuuu eecon2 ---- ---- ---- ---- ---- ---- table 15-4: initialization conditi ons for all registers (continued) register power-on reset, brown-out reset mclr reset, wdt reset wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in intcon, pir1 and pr2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 15-3 for reset value for specific condition.
? 2005 microchip technology inc. ds30487c-page 137 pic16f87/88 figure 15-3: time-out sequence on power-up (mclr tied to v dd through pull-up resistor) figure 15-4: time-out sequence on power-up (mclr tied to v dd through rc network): case 1 figure 15-5: time-out sequence on power-up (mclr tied to v dd through rc network): case 2 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost
pic16f87/88 ds30487c-page 138 ? 2005 microchip technology inc. figure 15-6: slow rise time (mclr tied to v dd through rc network) 15.10 interrupts the pic16f87/88 has up to 12 sources of interrupt. the interrupt control register (intcon) records individual interrupt requests in flag bits. it also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>), enables (if set) all unmasked interrupts, or disables (if cleared) all interrupts. when bit gie is enabled and an interrupt?s flag bit and mask bit are set, the interrupt will vector immediately. individual interrupts can be disabled through their corresponding enable bits in various registers. individual interrupt bits are set regardless of the status of the gie bit. the gie bit is cleared on reset. the ?return from interrupt? instruction, retfie , exits the interrupt routine, as well as sets the gie bit which re-enables interrupts. the rb0/int pin interrupt, the rb port change interrupt and the tmr0 overflow interrupt flags are contained in the intcon register. the peripheral interrupt flags are contained in the special function register, pir1. the corresponding interrupt enable bits are contained in special function register, pie1 and the peripheral interrupt enable bit is contained in special function register, intcon. when an interrupt is serviced, the gie bit is cleared to disable any further interrupt, the return address is pushed onto the stack and the pc is loaded with 0004h. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid recursive interrupts. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends on when the interrupt event occurs, relative to the current q cycle. the latency is the same for one or two cycle instructions. individual interrupt flag bits are set regardless of the status of their corresponding mask bit, peie bit or the gie bit. v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost note: individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the gie bit.
? 2005 microchip technology inc. ds30487c-page 139 pic16f87/88 figure 15-7: interrupt logic osfif osfie adif adie rcif rcie txif txie sspif sspie tmr2if tmr2ie tmr1if tmr1ie tmr0if tmr0ie int0if int0ie rbif rbie gie peie wake-up (if in sleep mode) interrupt to cpu eeif eeie ccp1if ccp1ie cmie cmif
pic16f87/88 ds30487c-page 140 ? 2005 microchip technology inc. 15.10.1 int interrupt external interrupt on the rb0/int pin is edge-triggered, either rising if bit intedg (option_reg<6>) is set, or falling if the intedg bit is clear. when a valid edge appears on the rb0/int pin, flag bit, int0if (intcon<1>), is set. this interrupt can be disabled by clearing enable bit int0ie (intcon<4>). flag bit int0if must be cleared in software in the interrupt service routine before re-enabling this interrupt. the int interrupt can wake-up the processor from sleep, if bit int0ie was set prior to going into sleep. the status of global interrupt enable bit gie decides whether or not the processor branches to the interrupt vector, following wake-up. see section 15.13 ?power-down mode (sleep)? for details on sleep mode. 15.10.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set flag bit tmr0if (intcon<2>). the interrupt can be enabled/disabled by setting/clearing enable bit tmr0ie (intcon<5>), see section 6.0 ?timer0 module? . 15.10.3 portb intcon change an input change on portb<7:4> sets flag bit rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit rbie (intcon<4>), see section 3.2 ?eecon1 and eecon2 registers? . 15.11 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key registers during an interrupt (i.e., w, status registers). since the upper 16 bytes of each bank are common in the pic16f87/88 devices, temporary holding registers w_temp, status_temp and pclath_temp should be placed in here. these 16 locations don?t require banking and therefore, make it easier for context save and restore. the same code shown in example 15-1 can be used. example 15-1: saving status, w and pclath registers in ram movwf w_temp ;copy w to temp register swapf status, w ;swap status to be saved into w clrf status ;bank 0, regardless of current bank, clears irp,rp1,rp0 movwf status_temp ;save status to bank zero status_temp register movf pclath, w ;only required if using page 1 movwf pclath_temp ;save pclath into w clrf pclath ;page zero, regardless of current page : :(isr) ;(insert user code here) : movf pclath_temp, w ;restore pclath movwf pclath ;move w into pclath swapf status_temp, w ;swap status_temp register into w ;(sets bank to original state) movwf status ;move w into status register swapf w_temp, f ;swap w_temp swapf w_temp, w ;swap w_temp into w
? 2005 microchip technology inc. ds30487c-page 141 pic16f87/88 15.12 watchdog timer (wdt) for pic16f87/88 devices, the wdt has been modified from previous pic16 devices. the new wdt is code and functionally backward compatible with previous pic16 wdt modules and allows the user to have a scaler value for the wdt and tmr0 at the same time. in addition, the wdt time-out value can be extended to 268 seconds, using the prescaler with the postscaler when psa is set to ? 1 ?. 15.12.1 wdt oscillator the wdt derives its time base from the 31.25 khz intrc. the value of wdtcon is ? ---0 1000 ? on all resets. this gives a nominal time base of 16.38 ms, which is compatible with the time base generated with previous pic16 microcontroller versions. a new prescaler has been added to the path between the internal rc and the multiplexors used to select the path for the wdt. this prescaler is 16 bits and can be programmed to divide the internal rc by 32 to 65536, giving the time base used for the wdt a nominal range of 1 ms to 2.097s. 15.12.2 wdt control the wdten bit is located in configuration word 1 and when this bit is set, the wdt runs continuously. the swdten bit is in the wdtcon register. when the wdten bit in the configuration word 1 register is set, the swdten bit has no effect. if wdten is clear, then the swdten bit can be used to enable and disable the wdt. setting the bit will enable it and clearing the bit will disable it. the psa and ps<2:0> bits (option_reg register) have the same function as in previous versions of the pic16 family of microcontrollers. figure 15-8: watchdog timer block diagram table 15-5: prescaler/postscaler bit status note: when the ost is invoked, the wdt is held in reset because the wdt ripple counter is used by the ost to perform the oscilla- tor delay count. when the ost count has expired, the wdt will begin counting (if enabled). conditions prescaler postscaler (psa = 1 ) wdten = 0 cleared cleared clrwdt command oscillator fail detected exit sleep + system clock = t1osc, extrc, intrc, ecio exit sleep + system clock = xt, hs, lp cleared at end of ost cleared at end of ost 31.25 khz psa 16-bit programmable prescaler wdt from tmr0 clock source postscaler 8 ps<2:0> psa wdt time-out to t m r 0 wdtps<3:0> wdten from configuration word 1 1 1 0 0 swdten from wdtcon intrc clock
pic16f87/88 ds30487c-page 142 ? 2005 microchip technology inc. register 15-3: wdtcon: watchdog control re gister (address 105h) table 15-6: summary of watchdog timer registers u-0 u-0 u-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten (1) bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps<3:0>: watchdog timer period select bits bit prescale value rate 0000 =1:32 0001 =1:64 0010 =1:128 0011 =1:256 0100 =1:512 0101 = 1:1024 0110 = 1:2048 0111 = 1:4096 1000 = 1:8192 1001 = 1:16394 1010 = 1:32768 1011 = 1:65536 bit 0 swdten: software enable/disable for watchdog timer bit (1) 1 = wdt is turned on 0 = wdt is turned off note 1: if wdten configuration bit = 1 , then wdt is always enabled, irrespective of this control bit. if wdten configuration bit = 0 , then it is possible to turn wdt on/off with this control bit. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 2007h configuration bits lvp boren mclre fosc2 pwrten wdten fosc1 fosc0 105h wdtcon ? ? ? wdtps3 wdtps2 wstps1 wdtps0 swdten legend: shaded cells are not used by the watchdog timer. note 1: see register 15-1 for operation of these bits.
? 2005 microchip technology inc. ds30487c-page 143 pic16f87/88 15.12.3 two-speed clock start-up mode two-speed start-up mode minimizes the latency between oscillator start-up and code execution that may be selected with the ieso (internal/external switchover) bit in configuration word 2. this mode is achieved by initially using the intrc for code execution until the primary oscillator is stable. if this mode is enabled and any of the following condi- tions exist, the system will begin execution with the intrc oscillator. this results in almost immediate code execution with a minimum of delay.  por and after the power-up timer has expired (if pwrten = 0 );  or following a wake-up from sleep;  or a reset when running from t1osc or intrc (after a reset, scs<1:0> are always set to ? 00 ?). if the primary oscillator is configured to be anything other than xt, lp or hs, then two-speed start-up mode is disabled because the primary oscillator will not require any time to become stable after por, or an exit from sleep. if the ircf bits of the osccon register are configured to a non-zero value prior to entering sleep mode, the system clock frequency will come from the output of the intosc. the iofs bit in the osccon register will be clear until the intosc is stable. this will allow the user to determine when the internal oscillator can be used for time critical applications. checking the state of the osts bit will confirm whether the primary clock configuration is engaged. if not, the osts bit will remain clear. when the device is auto-configured in intrc mode following a por or wake-up from sleep, the rules for entering other oscillator modes still apply, meaning the scs<1:0> bits in osccon can be modified before the ost time-out has occurred. this would allow the application to wake-up from sleep, perform a few instructions using the intrc as the clock source and go back to sleep without waiting for the primary oscillator to become stable. 15.12.3.1 two-speed start-up mode sequence 1. wake-up from sleep, reset or por. 2. osccon bits configured to run from intrc (31.25 khz). 3. instructions begin execution by intrc (31.25 khz). 4. ost enabled to count 1024 clock cycles. 5. ost timed out, wait for falling edge of intrc. 6. osts is set. 7. system clock held low for eight falling edges of new clock (lp, xt or hs). 8. system clock is switched to primary source (lp, xt or hs). the software may read the osts bit to determine when the switchover takes place so that any software timing edges can be adjusted. figure 15-9: two-speed start-up mode note: following any reset, the ircf bits are zeroed and the frequency selection is forced to 31.25 khz. the user can modify the ircf bits to select a higher internal oscillator frequency. note: executing a sleep instruction will abort the oscillator start-up time and will cause the osts bit to remain clear. q4 q1 q3 q4 q1 q2 osc1 sleep program pc 0000h intrc t ost q3 q4 osc2 osts system clock 0001h q1 q2 q3 q4 q1 q2 counter 0004h 0005h 0003h q1 q2 q3 q4 cpu start-up
pic16f87/88 ds30487c-page 144 ? 2005 microchip technology inc. 15.12.4 fail-safe option the fail-safe clock monitor (fscm) is designed to allow the device to continue to operate even in the event of an oscillator failure. figure 15-10: fscm block diagram the fscm function is enabled by setting the fcmen bit in configuration word 2. in the event of an oscillator failure, the fscm will generate an oscillator fail interrupt and will switch the system clock over to the internal oscillator. the system will continue to come from the internal oscillator until the fail-safe condition is exited. the fail-safe condition is exited with either a reset, the execution of a sleep instruction or a write to the osccon register. the frequency of the internal oscillator will depend upon the value contained in the ircf bits. another clock source can be selected via the ircf and the scs bits of the osccon register. the fscm sample clock is generated by dividing the intrc clock by 64. this will allow enough time between fscm sample clocks for a system clock edge to occur. on the rising edge of the postscaled clock, the monitoring latch (cm = 0 ) will be cleared. on a falling edge of the primary or secondary system clock, the monitoring latch will be set (cm = 1 ). in the event that a falling edge of the postscaled clock occurs and the monitoring latch is not set, a clock failure has been detected. while in fail-safe mode, a reset will exit the fail-safe condition. if the primary clock source is configured for a crystal, the ost timer will wait for the 1024 clock cycles for the ost time-out and the device will continue running from the internal oscillator until the ost is complete. a sleep instruction, or a write to the scs bits (where scs bits do not = 00 ), can be performed to put the device into a low-power mode. if reset occurs while in fail-safe mode and the pri- mary clock source is ec or rc, then the device will immediately switch back to ec or rc mode. 15.12.4.1 fail-safe in low-power mode a write to the osccon register, or sleep instruction, will end the fail-safe condition. the system clock will default to the source selected by the scs bits, which is either t1osc, intrc or none (sleep mode). how- ever, the fscm will continue to monitor the system clock. if the secondary clock fails, the device will immediately switch to the internal oscillator clock. if osfie is set, an interrupt will be generated. figure 15-11: fscm timing diagram peripheral intrc 64 s c q 31.25 khz (32 s) 488 hz (2.048 ms) clock monitor latch (cm) (edge-triggered) clock failure detected oscillator clock q note: two-speed start-up mode is automatically enabled when the fail-safe option is enabled. osfif cm output system clock output sample clock failure detected oscillator failure note: the system clock is normally at a much higher freq uency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test (488 hz)
? 2005 microchip technology inc. ds30487c-page 145 pic16f87/88 15.12.4.2 fscm and the watchdog timer when a clock failure is detected, scs<1:0> will be forced to ? 10 ? which will reset the wdt (if enabled). 15.12.4.3 por or wake from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary system clock is ec, rc or intrc modes, monitoring can begin immediately following these events. for oscillator modes involving a crystal or resonator (hs, lp or xt), the situation is somewhat different. since the oscillator may require a start-up time consid- erably longer than the fscm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically configured as the system clock and functions until the primary clock is stable (the ost timer has timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intrc returns to its role as the fscm source. 15.12.4.4 example fail-safe conditions 1. conditions: the device is clocked from a crystal, crystal operation fails and then sleep mode is entered. osts = 0 scs = 00 osfif = 1 user action: sleep mode will exit the fail-safe condition. therefore, if the user code did not handle the detected fail-safe prior to the sleep command, then upon wake-up, the device will try to start the crystal that failed and a fail-safe condition will not be detected. monitoring the osts bit will determine if the crystal is operating. the user should not enter sleep mode without handling the fail-safe condition first. 2. conditions: after a por (power-on reset), the device is running in two-speed start-up mode. the crys- tal fails before the ost has expired. if a crystal fails during the ost period, a fail-safe condition will not be detected (osfif will not get set). osts = 0 scs = 00 osfif = 0 user action: check the osts bit. if it?s clear and the ost should have expired at this point, then the user can assume the crystal has failed. the user should change the scs bit to cause a clock switch which will also release the 10-bit ripple counter for wdt operation (if enabled). 3. conditions: the device is clocked from a crystal during normal operation and it fails. osts = 0 scs = 00 osfif = 1 user action: clear the osfif bit. configure the scs bits for a clock switch and the fail-safe condition will be cleared. later, if the user decides to, the crystal can be retried for operation. if this is done, the osts bit should be monitored to determine if the crystal operates. 15.13 power-down mode (sleep) power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit (status<3>) is cleared, the to (status<4>) bit is set and the oscillator driver is turned off. the i/o ports maintain the status they had before the sleep instruction was executed (driving high, low or high-impedance). for lowest current consumption in this mode, place all i/o pins at either v dd or v ss , ensure no external cir- cuitry is drawing current from the i/o pin, power-down the a/d and disable external clocks. pull all i/o pins that are high-impedance inputs, high or low externally, to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for low- est current consumption. the contribution from on-chip pull-ups on portb should also be considered. the mclr pin must be at a logic high level (v ihmc ). note: the same logic that prevents false oscilla- tor failure interrupts on port or wake from sleep, will also prevent the detection of the oscillator?s failure to start at all follow- ing these events. this can be avoided by monitoring the osts bit and using a timing routine to determine if the oscillator is taking too long to start. even so, no oscillator failure interrupt will be flagged.
pic16f87/88 ds30487c-page 146 ? 2005 microchip technology inc. 15.13.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from int pin, rb port change or a peripheral interrupt. external mclr reset will cause a device reset. all other events are considered a continuation of program execution and cause a ?wake-up?. the to and pd bits in the status register can be used to determine the cause of the device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. the to bit is cleared if a wdt time-out occurred and caused wake-up. the following peripheral interrupts can wake the device from sleep: 1. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 2. ccp capture mode interrupt. 3. special event trigger (timer1 in asynchronous mode using an external clock). 4. ssp (start/stop) bit detect interrupt. 5. ssp transmit or receive in slave mode (spi/i 2 c). 6. a/d conversion (when a/d clock source is rc). 7. eeprom write operation completion. 8. comparator output changes state. 9. ausart rx or tx (synchronous slave mode). other peripherals cannot generate interrupts, since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is prefetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up occurs regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the interrupt address (0004h). in cases where the execu- tion of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. 15.13.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur:  if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will complete as a nop . therefore, the wdt and wdt prescaler and postscaler (if enabled) will not be cleared, the to bit will not be set and the pd bit will not be cleared.  if the interrupt occurs during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt prescaler and postscaler (if enabled) will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction. figure 15-12: wake-up from sleep through interrupt (1) q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clko (4) int pin int0if flag (intcon<1>) gie bit (3) (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc + 1 pc + 2 inst(pc) = sleep inst(pc ? 1) inst(pc + 1) sleep processor in sleep interrupt latency (note 2) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle t ost (2) pc + 2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024 t osc (drawing not to scale). this delay will not be there for rc oscillator mode. 3: gie = 1 assumed. in this case, after wake-up, the processor jumps to the interrupt routine. if gie = 0 , execution will continue in-line. 4: clko is not available in these oscillator modes, but shown here for timing reference.
? 2005 microchip technology inc. ds30487c-page 147 pic16f87/88 15.14 in-circuit debugger when the debug bit in the configuration word is programmed to a ? 0 ?, the in-circuit debugger function- ality is enabled. this function allows simple debugging functions when used with mplab ? icd. when the microcontroller has this feature enabled, some of the resources are not available for general use. table 15-7 shows which features are consumed by the background debugger. table 15-7: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to ra5/m clr /v pp , v dd , gnd, rb7 and rb6. this will interface to the in-circuit debugger module available from microchip, or one of the third party development tool companies. 15.15 program verification/code protection if the code protection bit(s) have not been programmed, the on-chip program memory can be read out for verification purposes. 15.16 id locations four memory locations (2000h-2003h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution but are readable and writable during program/verify. it is recommended that only the four least significant bits of the id location are used. 15.17 in-circuit serial programming pic16f87/88 microcontrollers can be serially pro- grammed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage (see figure 15-13 for an example). this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. for more information on serial programming, please refer to the ?pic16f87/88 flash memory programming specification? (ds39607). figure 15-13: typical in-circuit serial programming connection i/o pins rb6, rb7 stack 1 level program memory address 0000h must be nop last 100h words data memory 0x070 (0x0f0, 0x170, 0x1f0) 0x1eb-0x1ef note: the timer1 oscillator shares the t1osi and t1oso pins with the pgd and pgc pins used for programming and debugging. when using the timer1 oscillator, in- circuit serial programming? (icsp?) may not function correctly (high voltage or low voltage), or the in-circuit debugger (icd) may not communicate with the controller. as a result of using either icsp or icd, the timer1 crystal may be damaged. if icsp or icd operations are required, the crystal should be disconnected from the circuit (disconnect either lead), or installed after programming. the oscillator loading capacitors may remain in-circuit during icsp or icd operation. external connector signals to normal connections to n o r m a l connections pic16f87/88 v dd v ss ra5/mclr /v pp rb6 rb7 +5v 0v v pp clk data i/o v dd * * * * * isolation devices (as required). ? rb3 only used in lvp mode. rb3 ? rb3/pgm
pic16f87/88 ds30487c-page 148 ? 2005 microchip technology inc. 15.18 low-voltage icsp programming the lvp bit of the configuration word enables low- voltage icsp programming. this mode allows the microcontroller to be programmed via icsp using a v dd source in the operating voltage range. this only means that v pp does not have to be brought to v ihh , but can instead be left at the normal operating voltage. in this mode, the rb3/pgm pin is dedicated to the programming function and ceases to be a general purpose i/o pin. if low-voltage programming mode is not used, the lvp bit can be programmed to a ? 0 ? and rb3/pgm becomes a digital i/o pin. however, the lvp bit may only be programmed when programming mode is entered with v ihh on mclr . the lvp bit can only be changed when using high voltage on mclr . it should be noted that once the lvp bit is programmed to ? 0 ?, only the high-voltage programming mode is available and only this mode can be used to program the device. when using low-voltage icsp, the part must be supplied at 4.5v to 5.5v if a bulk erase will be executed. this includes reprogramming of the code-protect bits from an on state to an off state. for all other cases of low-voltage icsp, the part may be programmed at the normal operating voltage. this means calibration values, unique user ids or user code can be reprogrammed or added. the following lvp steps assume the lvp bit is set in the configuration register. 1. apply v dd to the v dd pin. 2. drive mclr low. 3. apply v dd to the rb3/pgm pin. 4. apply v dd to the mclr pin. 5. follow with the associated programming steps. note 1: the high-voltage programming mode is always available, regardless of the state of the lvp bit, by applying v ihh to the mclr pin. 2: while in low-voltage icsp mode (lvp = 1 ), the rb3 pin can no longer be used as a general purpose i/o pin. 3: when using low-voltage icsp program- ming (lvp) and the pull-ups on portb are enabled, bit 3 in the trisb register must be cleared to disable the pull-up on rb3 and ensure the proper operation of the device. 4: rb3 should not be allowed to float if lvp is enabled. an external pull-down device should be used to default the device to normal operating mode. if rb3 floats high, the pic16f87/88 devices will enter programming mode. 5: lvp mode is enabled by default on all devices shipped from microchip. it can be disabled by clearing the lvp bit in the config1 register. 6: disabling lvp will provide maximum compatibility to other pic16cxxx devices.
? 2005 microchip technology inc. ds30487c-page 149 pic16f87/88 16.0 instruction set summary the pic16 instruction set is highly orthogonal and is comprised of three basic categories:  byte-oriented operations  bit-oriented operations  literal and control operations each pic16 instruction is a 14-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the formats for each of the categories are presented in figure 16-1, while the various opcode fields are summarized in table 16-1. table 16-2 lists the instructions recognized by the mpasm tm assembler. a complete description of each instruction is also available in the ?picmicro ? mid-range mcu family reference manual? (ds33023). for byte-oriented instructions, ?f? represents a file register designator and ?d? represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the w register. if ?d? is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, ?b? represents a bit field designator, which selects the bit affected by the opera- tion, while ?f? represents the address of the file in which the bit is located. for literal and control operations, ?k? represents an eight or eleven-bit constant or literal value one instruction cycle consists of four oscillator periods. for an oscillator frequency of 4 mhz, this gives a normal instruction execution time of 1 s. all instruc- tions are executed within a single instruction cycle, unless a conditional test is true, or the program counter is changed as a result of an instruction. when this occurs, the execution takes two instruction cycles, with the second cycle executed as a nop . all instruction examples use the format ? 0xhh ? to repre- sent a hexadecimal number, where ? h ? signifies a hexadecimal digit. 16.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (rmw) operation. the register is read, the data is modified and the result is stored according to either the instruction, or the destination designator ?d?. a read operation is performed on a register even if the instruction writes to that register. for example, a ? clrf portb ? instruction will read portb, clear all the data bits, then write the result back to portb. this example would have the unintended result that the condition that sets the rbif flag would be cleared. table 16-1: opcode field descriptions figure 16-1: general format for instructions note: to maintain upward compatibility with future pic16f87/88 products, do not use the option and tris instructions. field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don't care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w, d = 1 : store result in file register f. default is d = 1. pc program counter to time-out bit pd power-down bit byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
pic16f87/88 ds30487c-page 150 ? 2005 microchip technology inc. table 16-2: pic16f87/88 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f - f, d f, d f, d f, d f, d f, d f, d f - f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1(2) 1 1(2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1,2 1,2 2 1,2 1,2 1,2,3 1,2 1,2,3 1,2 1,2 1,2 1,2 1,2 1,2 1,2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1,2 1,2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k - k k k - k - - k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to , pd z to , pd c,dc,z z note 1: when an i/o register is modified as a function of itself (e.g., movf portb, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tm r0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if the program counter (pc) is modified or a conditional te st is true, the instruction requires two cycles. the second cycle is executed as a nop . note: additional information on the mid-range instruction set is available in the ? picmicro ? mid-range mcu family reference manual? (ds33023).
? 2005 microchip technology inc. ds30487c-page 151 pic16f87/88 16.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal ?k? and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [0,1] operation: (w) + (f) (destination) status affected: c, dc, z description: add the contents of the w register with register ?f?. if ?d? = 0 , the result is stored in the w register. if ?d? = 1 , the result is stored back in register ?f?. andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal ?k?. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [0,1] operation: (w) .and. (f) (destination) status affected: z description: and the w register with register ?f?. if ?d? = 0 , the result is stored in the w register. if ?d? = 1 , the result is stored back in register ?f?. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none description: bit ?b? in register ?f? is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none description: bit ?b? in register ?f? is set.
pic16f87/88 ds30487c-page 152 ? 2005 microchip technology inc. btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none description: if bit ?b? in register ?f? = 0 , the next instruction is executed. if bit ?b? = 1 , then the next instruction is discarded and a nop is executed instead, making this a 2t cy instruction. btfsc bit test, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none description: if bit ?b? in register ?f? = 1 , the next instruction is executed. if bit ?b?, in register ?f?, = 0 , the next instruction is discarded and a nop is executed instead, making this a 2 t cy instruction. call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc) + 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none description: call subroutine. first, return address (pc + 1) is pushed onto the stack. the eleven-bit immediate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f), 1 z status affected: z description: the contents of register ?f? are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w), 1 z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 1 pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set.
? 2005 microchip technology inc. ds30487c-page 153 pic16f87/88 comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f) (destination) status affected: z description: the contents of register ?f? are complemented. if ?d? = 0 , the result is stored in w. if ?d? = 1 , the result is stored back in register ?f?. decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) ? 1 (destination) status affected: z description: decrement register ?f?. if ?d? = 0 , the result is stored in the w register. if ?d? = 1 , the result is stored back in register ?f?. decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) ? 1 (destination); skip if result = 0 status affected: none description: the contents of register ?f? are decremented. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, then a nop is executed instead, making it a 2t cy instruction. goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0>, pclath<4:3> pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination) status affected: z description: the contents of register ?f? are incremented. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is placed back in register ?f?. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination), skip if result = 0 status affected: none description: the contents of register ?f? are incremented. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, a nop is executed instead, making it a 2 t cy instruction.
pic16f87/88 ds30487c-page 154 ? 2005 microchip technology inc. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z description: the contents of the w register are or?ed with the eight-bit literal ?k?. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (destination) status affected: z description: inclusive or the w register with register ?f?. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is placed back in register ?f?. movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (destination) status affected: z description: the contents of register ?f? are moved to a destination dependant upon the status of ?d?. if ?d? = 0 , the destination is w register. if ?d? = 1 , the destination is file register ?f? itself. ?d? = 1 is useful to test a file register, since status flag z is affected. movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none description: the eight-bit literal ?k? is loaded into w register. the don?t cares will assemble as ? 0 ?s. movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none description: move data from w register to register ?f?. nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none description: no operation.
? 2005 microchip technology inc. ds30487c-page 155 pic16f87/88 retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none description: the w register is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction. rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is stored back in register ?f?. rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? = 0 , the result is placed in the w register. if ?d? = 1 , the result is placed back in register ?f?. sleep sleep syntax: [ label ]sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd description: the power-down status bit, pd , is cleared. time-out status bit, to , is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. register f c register f c
pic16f87/88 ds30487c-page 156 ? 2005 microchip technology inc. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k ? (w) ( w) status affected: c, dc, z description: the w register is subtracted (two?s complement method) from the eight-bit literal ?k?. the result is placed in the w register. subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) ? (w) ( destination) status affected: c, dc, z description: subtract (two?s complement method) w register from register ?f?. if ?d? = 0 , the result is stored in the w register. if ?d? = 1 , the result is stored back in register ?f?. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (destination<7:4>), (f<7:4>) (destination<3:0>) status affected: none description: the upper and lower nibbles of register ?f? are exchanged. if ?d? = 0 , the result is placed in w register. if ?d? = 1 , the result is placed in register ?f?. xorlw exclusive or literal with w syntax: [ label ]xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z description: the contents of the w register are xor?ed with the eight-bit literal ?k?. the result is placed in the w register. xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( destination) status affected: z description: exclusive or the contents of the w register with register ?f?. if ?d? = 0 , the result is stored in the w register. if ?d? = 1 , the result is stored back in register ?f?.
? 2005 microchip technology inc. ds30487c-page 157 pic16f87/88 17.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools:  integrated development environment - mplab ? ide software  assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian - mplab c30 c compiler - mplab asm30 assembler/linker/library  simulators - mplab sim software simulator - mplab dspic30 software simulator emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator  in-circuit debugger - mplab icd 2  device programmers -pro mate ? ii universal device programmer - picstart ? plus development programmer - mplab pm3 device programmer  low-cost demonstration boards - picdem tm 1 demonstration board - picdem.net tm demonstration board - picdem 2 plus demonstration board - picdem 3 demonstration board - picdem 4 demonstration board - picdem 17 demonstration board - picdem 18r demonstration board - picdem lin demonstration board - picdem usb demonstration board  evaluation kits -k ee l oq ? evaluation and programming tools - picdem msc -microid ? developer kits -can - powersmart ? developer kits -analog 17.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? based application that contains:  an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately)  a full-featured editor with color coded context  a multiple project manager  customizable data windows with direct edit of contents  high-level source code debugging  mouse over variable inspection  extensive on-line help the mplab ide allows you to:  edit your source files (either assembly or c)  one touch assemble (or compile) and download to picmicro emulator and simulator tools (automatically updates all project information)  debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increasing flexibility and power. 17.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol ref- erence, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include:  integration into mplab ide projects  user defined macros to streamline assembly code  conditional assembly for multi-purpose source files  directives that allow complete control over the assembly process
pic16f87/88 ds30487c-page 158 ? 2005 microchip technology inc. 17.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi c compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 17.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include:  efficient linking of single libraries instead of many smaller files  enhanced code maintainability by grouping related modules together  flexible creation of libraries with easy module listing, replacement, deletion and extraction 17.5 mplab c30 c compiler the mplab c30 c compiler is a full-featured, ansi compliant, optimizing compiler that translates standard ansi c programs into dspic30f assembly language source. the compiler also supports many command line options and language extensions to take full advantage of the dspic30f device hardware capabili- ties and afford fine control of the compiler code generator. mplab c30 is distributed with a complete ansi c standard library. all library functions have been vali- dated and conform to the ansi c library standard. the library includes functions for string manipulation, dynamic memory allocation, data conversion, time- keeping and math functions (trigonometric, exponential and hyperbolic). the compiler provides symbolic information for high-level source debugging with the mplab ide. 17.6 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 compiler uses the assembler to produce it?s object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include:  support for the entire dspic30f instruction set  support for fixed-point and floating-point data  command line interface  rich directive set  flexible macro language  mplab ide compatibility 17.7 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any pin. the execu- tion can be performed in single-step, execute until break or trace mode. the mplab sim simulator fully supports symbolic debugging using the mplab c17 and mplab c18 c compilers, as well as the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool. 17.8 mplab sim30 software simulator the mplab sim30 software simulator allows code development in a pc hosted environment by simulating the dspic30f series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any of the pins. the mplab sim30 simulator fully supports symbolic debugging using the mplab c30 c compiler and mplab asm30 assembler. the simulator runs in either a command line mode for automated tasks, or from mplab ide. this high-speed simulator is designed to debug, analyze and optimize time intensive dsp routines.
? 2005 microchip technology inc. ds30487c-page 159 pic16f87/88 17.9 mplab ice 2000 high-performance universal in-circuit emulator the mplab ice 2000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 17.10 mplab ice 4000 high-performance universal in-circuit emulator the mplab ice 4000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high- end picmicro microcontrollers. software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab icd 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high-speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, up to 2 mb of emulation memory and the ability to view variables in real-time. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 17.11 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro microcontrollers. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single-stepping and watching variables, cpu status and peripheral registers. running at full speed enables testing hardware and applications in real-time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 17.12 pro mate ii universal device programmer the pro mate ii is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features an lcd display for instructions and error messages and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. 17.13 mplab pm3 device programmer the mplab pm3 is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modular detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand- alone mode, the mplab pm3 device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. mplab pm3 connects to the host pc via an rs- 232 or usb cable. mplab pm3 has high-speed com- munications and optimized algorithms for quick pro- gramming of large memory devices and incorporates an sd/mmc card for file storage and secure data appli- cations.
pic16f87/88 ds30487c-page 160 ? 2005 microchip technology inc. 17.14 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 17.15 picdem 1 picmicro demonstration board the picdem 1 demonstration board demonstrates the capabilities of the pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the sample microcontrollers provided with the picdem 1 demonstration board can be programmed with a pro mate ii device program- mer or a picstart plus development programmer. the picdem 1 demonstration board can be connected to the mplab ice in-circuit emulator for testing. a prototype area extends the circuitry for additional appli- cation components. features include an rs-232 interface, a potentiometer for simulated analog input, push button switches and eight leds. 17.16 picdem.net internet/ethernet demonstration board the picdem.net demonstration board is an internet/ ethernet demonstration board using the pic18f452 microcontroller and tcp/ip firmware. the board supports any 40-pin dip device that conforms to the standard pinout used by the pic16f877 or pic18c452. this kit features a user friendly tcp/ip stack, web server with html, a 24l256 serial eeprom for xmodem download to web pages into serial eeprom, icsp/mplab icd 2 interface con- nector, an ethernet interface, rs-232 interface and a 16 x 2 lcd display. also included is the book and cd-rom ?tcp/ip lean, web servers for embedded systems,? by jeremy bentham 17.17 picdem 2 plus demonstration board the picdem 2 plus demonstration board supports many 18, 28 and 40-pin microcontrollers, including pic16f87x and pic18fxx2 devices. all the neces- sary hardware and software is included to run the dem- onstration programs. the sample microcontrollers provided with the picdem 2 demonstration board can be programmed with a pro mate ii device program- mer, picstart plus development programmer, or mplab icd 2 with a universal programmer adapter. the mplab icd 2 and mplab ice in-circuit emulators may also be used with the picdem 2 demonstration board to test firmware. a prototype area extends the circuitry for additional application components. some of the features include an rs-232 interface, a 2 x 16 lcd display, a piezo speaker, an on-board temperature sensor, four leds and sample pic18f452 and pic16f877 flash microcontrollers. 17.18 picdem 3 pic16c92x demonstration board the picdem 3 demonstration board supports the pic16c923 and pic16c924 in the plcc package. all the necessary hardware and software is included to run the demonstration programs. 17.19 picdem 4 8/14/18-pin demonstration board the picdem 4 can be used to demonstrate the capa- bilities of the 8, 14 and 18-pin pic16xxxx and pic18xxxx mcus, including the pic16f818/819, pic16f87/88, pic16f62xa and the pic18f1320 family of microcontrollers. picdem 4 is intended to showcase the many features of these low pin count parts, including lin and motor control using eccp. special provisions are made for low-power operation with the supercapacitor circuit and jumpers allow on- board hardware to be disabled to eliminate current draw in this mode. included on the demo board are pro- visions for crystal, rc or canned oscillator modes, a five volt regulator for use with a nine volt wall adapter or battery, db-9 rs-232 interface, icd connector for programming via icsp and development with mplab icd 2, 2 x 16 liquid crystal display, pcb footprints for h-bridge motor driver, lin transceiver and eeprom. also included are: header for expansion, eight leds, four potentiometers, three push buttons and a proto- typing area. included with the kit is a pic16f627a and a pic18f1320. tutorial firmware is included along with the user?s guide.
? 2005 microchip technology inc. ds30487c-page 161 pic16f87/88 17.20 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. a pro- grammed sample is included. the pro mate ii device programmer, or the picstart plus development pro- grammer, can be used to reprogram the device for user tailored application development. the picdem 17 demonstration board supports program download and execution from external on-board flash memory. a generous prototype area is available for user hardware expansion. 17.21 picdem 18r pic18c601/801 demonstration board the picdem 18r demonstration board serves to assist development of the pic18c601/801 family of microchip microcontrollers. it provides hardware implementation of both 8-bit multiplexed/demultiplexed and 16-bit memory modes. the board includes 2 mb external flash memory and 128 kb sram memory, as well as serial eeprom, allowing access to the wide range of memory types supported by the pic18c601/801. 17.22 picdem lin pic16c43x demonstration board the powerful lin hardware and software kit includes a series of boards and three picmicro microcontrollers. the small footprint pic16c432 and pic16c433 are used as slaves in the lin communication and feature on-board lin transceivers. a pic16f874 flash microcontroller serves as the master. all three micro- controllers are programmed with firmware to provide lin bus communication. 17.23 pickit tm 1 flash starter kit a complete ?development system in a box?, the pickit? flash starter kit includes a convenient multi-section board for programming, evaluation and development of 8/14-pin flash pic ? microcontrollers. powered via usb, the board operates under a simple windows gui. the pickit 1 starter kit includes the user?s guide (on cd rom), pickit 1 tutorial software and code for various applications. also included are mplab ? ide (integrated development environment) software, software and hardware ?tips 'n tricks for 8-pin flash pic ? microcontrollers? handbook and a usb interface cable. supports all current 8/14-pin flash pic microcontrollers, as well as many future planned devices. 17.24 picdem usb pic16c7x5 demonstration board the picdem usb demonstration board shows off the capabilities of the pic16c745 and pic16c765 usb microcontrollers. this board provides the basis for future usb products. 17.25 evaluation and programming tools in addition to the picdem series of circuits, microchip has a line of evaluation kits and demonstration software for these products. k ee l oq evaluation and programming tools for microchip?s hcs secure data products  can developers kit for automotive network applications  analog design boards and filter design software  powersmart battery charging evaluation/ calibration kits irda ? development kit  microid development and rflab tm development software  seeval ? designer kit for memory evaluation and endurance calculations  picdem msc demo boards for switching mode power supply, high-power ir driver, delta sigma adc and flow rate sensor check the microchip web page and the latest product selector guide for the complete list of demonstration and evaluation kits.
pic16f87/88 ds30487c-page 162 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 163 pic16f87/88 18.0 electrical characteristics absolute maximum ratings ? ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd and m clr ) ................................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ............................................................................................................ -0.3 to +7.5v voltage on mclr with respect to v ss (note 2) .............................................................................................-0.3 to +14v total power dissipation (note 1) ............................................................................................................................... ...1w maximum current out of v ss pin ........................................................................................................................... 200 ma maximum current into v dd pin ........................................................................................................................... ...200 ma input clamp current, i ik (v i < 0 or v i > v dd ) ...................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by porta ........................................................................................................................10 0 ma maximum current sourced by porta............................................................................................... ....................100 ma maximum current sunk by portb........................................................................................................................10 0 ma maximum current sourced by portb ............................................................................................... ...................100 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v ol x i ol ) 2: voltage spikes at the mclr pin may cause latch-up. a series resistor of greater than 1 k ? should be used to pull mclr to v dd , rather than tying the pin directly to v dd . ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic16f87/88 ds30487c-page 164 ? 2005 microchip technology inc. figure 18-1: pic16f87/88 voltage-frequency graph (industrial, extended) figure 18-2: pic16lf87/88 voltage-frequency graph (industrial) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 20 mhz 5.0v 3.5v 3.0v 2.5v 16 mhz frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 5.0v 3.5v 3.0v 2.5v f max = (12 mhz/v) (v ddappmin ? 2.5v) + 4 mhz note 1: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 10 mhz note 2: f max has a maximum frequency of 10 mhz.
? 2005 microchip technology inc. ds30487c-page 165 pic16f87/88 18.1 dc characteristics: supply voltage pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. symbol characteristic min typ max units conditions v dd supply voltage d001 pic16lf87/88 2.0 ? 5.5 v hs, xt, rc and lp oscillator mode d001 pic16f87/88 4.0 ? 5.5 v d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ? ? 0.7 v see section 15.4 ?power-on reset (por)? for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 15.4 ?power-on reset (por)? for details v bor brown-out reset voltage d005 pic16lf87/88 3.65 ? 4.35 v d005 pic16f87/88 3.65 ? 4.35 v f max = 14 mhz (2) legend: shading of rows is to assist in readability of the table. note 1: this is the limit to which v dd can be lowered in sleep mode, or duri ng a device reset, without losing ram data. 2: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
pic16f87/88 ds30487c-page 166 ? 2005 microchip technology inc. 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions power-down current (i pd ) (1) pic16lf87/88 0.1 0.4 a -40c 0.1 0.4 a +25c v dd = 2.0v 0.4 1.5 a +85c pic16lf87/88 0.3 0.5 a -40c 0.3 0.5 a +25c v dd = 3.0v 0.7 1.7 a +85c all devices 0.6 1.0 a -40c v dd = 5.0v 0.6 1.0 a +25c 1.2 5.0 a +85c extended devices 6 28 a +125c legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2005 microchip technology inc. ds30487c-page 167 pic16f87/88 supply current (i dd ) (2,3) pic16lf87/88 9 20 a -40c f osc = 32 kh z (lp oscillator) 715 a +25c v dd = 2.0v 715 a +85c pic16lf87/88 16 30 a -40c 14 25 a +25c v dd = 3.0v 14 25 a +85c all devices 32 40 a -40c v dd = 5.0v 26 35 a +25c 26 35 a +85c extended devices 35 53 a +125c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic16f87/88 ds30487c-page 168 ? 2005 microchip technology inc. supply current (i dd ) (2,3) pic16lf87/88 72 95 a -40c v dd = 2.0v f osc = 1 mh z (rc oscillator) (3) 76 90 a +25c 76 90 a +85c pic16lf87/88 138 175 a -40c 136 170 a +25c v dd = 3.0v 136 170 a +85c all devices 310 380 a -40c v dd = 5.0v 290 360 a +25c 280 360 a +85c extended devices 330 500 a 125c pic16lf87/88 270 335 a -40c f osc = 4 mhz (rc oscillator) (3) 280 330 a +25c v dd = 2.0v 285 330 a +85c pic16lf87/88 460 610 a -40c 450 600 a +25c v dd = 3.0v 450 600 a +85c all devices 900 1060 a -40c v dd = 5.0v 890 1050 a +25c 890 1050 a +85c extended devices .920 1.5 ma +125c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2005 microchip technology inc. ds30487c-page 169 pic16f87/88 supply current (i dd ) (2,3) all devices 1.8 2.3 ma -40c f osc = 20 mh z (hs oscillator) 1.6 2.2 ma +25c v dd = 4.0v 1.3 2.2 ma +85c all devices 3.0 4.2 ma -40c v dd = 5.0v 2.5 4.0 ma +25c 2.5 4.0 ma +85c extended devices 3.0 5.0 ma +85c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic16f87/88 ds30487c-page 170 ? 2005 microchip technology inc. supply current (i dd ) (2,3) pic16lf87/88 8 20 a -40c f osc = 31.25 khz ( rc_run mode, internal rc oscillator) 715 a +25c v dd = 2.0v 715 a +85c pic16lf87/88 16 30 a -40c 14 25 a +25c v dd = 3.0v 14 25 a +85c all devices 32 40 a -40c v dd = 5.0v 29 35 a +25c 29 35 a +85c extended devices 35 45 a +125c pic16lf87/88 132 160 a -40c f osc = 1 mhz ( rc_run mode, internal rc oscillator) 126 155 a +25c v dd = 2.0v 126 155 a +85c pic16lf87/88 260 310 a -40c 230 300 a +25c v dd = 3.0v 230 300 a +85c all devices 560 690 a -40c v dd = 5.0v 500 650 a +25c 500 650 a +85c extended devices 570 710 a +125c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2005 microchip technology inc. ds30487c-page 171 pic16f87/88 supply current (i dd ) (2,3) pic16lf87/88 310 420 a -40c f osc = 4 mhz ( rc_run mode, internal rc oscillator) 300 410 a +25c v dd = 2.0v 300 410 a +85c pic16lf87/88 550 650 a -40c 530 620 a +25c v dd = 3.0v 530 620 a +85c all devices 1.2 1.5 ma -40c v dd = 5.0v 1.1 1.4 ma +25c 1.1 1.4 ma +85c extended devices 1.3 1.6 ma +125c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic16f87/88 ds30487c-page 172 ? 2005 microchip technology inc. supply current (i dd ) (2,3) pic16lf87/88 .950 1.3 ma -40c f osc = 8 mhz ( rc_run mode, internal rc oscillator) .930 1.2 ma +25c v dd = 3.0v .930 1.2 ma +85c all devices 1.8 3.0 ma -40c v dd = 5.0v 1.7 2.8 ma +25c 1.7 2.8 ma +85c extended devices 2.0 4.0 ma +125c pic16lf87/88 9 13 a -10c f osc = 32 khz ( sec_run mode, timer1 as clock) 914 a +25c v dd = 2.0v 11 16 a +70c pic16lf87/88 12 34 a -10c 12 31 a +25c v dd = 3.0v 14 28 a +70c all devices 20 72 a -10c 20 65 a +25c v dd = 5.0v 25 59 a +70c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
? 2005 microchip technology inc. ds30487c-page 173 pic16f87/88 d022 ( ? i wdt ) module differential currents ( ? i wdt , ? i bor , ? i lvd , ? i oscb , ? i ad ) watchdog timer 1.5 3.8 a -40c 2.2 3.8 a +25c v dd = 2.0v 2.7 4.0 a +85c 2.3 4.6 a -40c 2.7 4.6 a +25c v dd = 3.0v 3.1 4.8 a +85c 3.0 10.0 a -40c v dd = 5.0v 3.3 10.0 a +25c 3.9 13.0 a +85c extended devices 5.0 21.0 a +125c d022a ( ? i bor ) brown-out reset 40 60 a-40 c to +85 cv dd = 5.0v d025 ( ? i oscb ) timer1 oscillator 1.7 2.3 a -40c 32 khz on timer1 1.8 2.3 a +25c v dd = 2.0v 2.0 2.3 a +85c 2.2 3.8 a -40c 2.6 3.8 a +25c v dd = 3.0v 2.9 3.8 a +85c 3.0 6.0 a -40c 3.2 6.0 a +25c v dd = 5.0v 3.4 7.0 a +85c d026 ( ? i ad ) a/d converter 0.001 2.0 a-40 c to +85 cv dd = 2.0v a/d on, sleep, not converting 0.001 2.0 a-40 c to +85 cv dd = 3.0v 0.003 2.0 a-40 c to +85 c v dd = 5.0v extended devices 4.0 8.0 a-40 c to +125 c 18.2 dc characteristics: power-down and supply current pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? .
pic16f87/88 ds30487c-page 174 ? 2005 microchip technology inc. 18.3 dc characteristics: internal rc accuracy pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) pic16lf87/88 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic16f87/88 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device min typ max units conditions intosc accuracy @ freq = 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz, 125 khz (1) pic16lf87/88 -2 1 2 % +25c v dd = 2.7-3.3v -5 ? 5 % -10c to +85c -10 ? 10 % -40c to +85c pic16f87/88 -2 1 2 % 25c v dd = 4.5-5.5v -5 ? 5 % -10c to +85c -10 ? 10 % -40c to +85c extended devices -15 ? 15 % -40c to +125c v dd = 4.5-5.5v intrc accuracy @ freq = 31 khz (2) pic16lf87/88 26.562 ? 35.938 khz -40c to +85c v dd = 2.7-3.3v pic16f87/88 26.562 ? 35.938 khz -40c to +85c v dd = 4.5-5.5v legend: shading of rows is to assist in readability of the table. note 1: frequency calibrated at 25c. osctune register can be used to compensate for temperature drift. 2: intrc frequency after calibration.
? 2005 microchip technology inc. ds30487c-page 175 pic16f87/88 18.4 dc characteristics: pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended operating voltage v dd range as described in dc specification, section 18.1 ?dc characteristics: supply voltage? . param no. sym characteristic min typ? max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss ?0.15 v dd v for entire v dd range d030a v ss ?0.8v v4.5v v dd 5.5v d031 with schmitt trigger buffer v ss ? 0.2 v dd v d032 mclr , osc1 (in rc mode) v ss ? 0.2 v dd v (note 1) d033 osc1 (in xt and lp mode) v ss ?0.3v v osc1 (in hs mode) v ss ? 0.3 v dd v ports rb1 and rb4: d034 with schmitt trigger buffer v ss ? 0.3 v dd v for entire v dd range v ih input high voltage i/o ports: d040 with ttl buffer 2.0 ? v dd v4.5v v dd 5.5v d040a 0.25 v dd + 0.8v ? v dd v for entire v dd range d041 with schmitt trigger buffer 0.8 v dd ?v dd v for entire v dd range d042 mclr 0.8 v dd ?v dd v d042a osc1 (in xt and lp mode) 1.6v ? v dd v osc1 (in hs mode) 0.7 v dd ?v dd v d043 osc1 (in rc mode) 0.9 v dd ?v dd v (note 1) ports rb1 and rb4: d044 with schmitt trigger buffer 0.7 v dd ?v dd v for entire v dd range d070 i purb portb weak pull-up current 50 250 400 av dd = 5v, v pin = v ss i il input leakage current (notes 2, 3) d060 i/o ports ? ? 1 avss v pin v dd , pin at high-impedance d061 mclr ? ? 5 avss v pin v dd d063 osc1 ? ? 5 avss v pin v dd , xt, hs and lp oscillator configuration * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f87/88 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage cu rrent may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
pic16f87/88 ds30487c-page 176 ? 2005 microchip technology inc. v ol output low voltage d080 i/o ports ? ? 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +125 c d083 osc2/clko (rc oscillator configuration) ??0.6vi ol = 1.6 ma, v dd = 4.5v, -40 c to +125 c v oh output high voltage d090 i/o ports (note 3) v dd ? 0.7 ? ? v i oh = -3.0 ma, v dd = 4.5v, -40 c to +125 c d092 osc2/clko (rc oscillator configuration) v dd ? 0.7 ? ? v i oh = -1.3 ma, v dd = 4.5v, -40 c to +125 c capacitive loading specs on output pins d100 c osc2 osc2 pin ? ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 c io all i/o pins and osc2 (in rc mode) ??50pf d102 c b scl, sda in i 2 c? mode ??400pf data eeprom memory d120 e d endurance 100k 10k 1m 100k ? ? e/w e/w -40 c to 85 c +85 c to +125 c d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write, v min = min. operating voltage d122 t dew erase/write cycle time ? 4 8 ms program flash memory d130 e p endurance 10k 1k 100k 10k ? ? e/w e/w -40 c to 85 c +85 c to +125 c d131 v pr v dd for read v min ?5.5 v d132a v dd for erase/write v min ? 5.5 v using eecon to read/write, v min = min. operating voltage d133 t pe erase cycle time ? 2 4 ms d134 t pw write cycle time ? 2 4 ms 18.4 dc characteristics: pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended operating voltage v dd range as described in dc specification, section 18.1 ?dc characteristics: supply voltage? . param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the pic16f87/88 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage cu rrent may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
? 2005 microchip technology inc. ds30487c-page 177 pic16f87/88 table 18-1: comparator specifications table 18-2: voltage reference specifications operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c, unless otherwise stated param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 10 mv d301 v icm input common mode voltage* 0 ? v dd ? 1.5 v d302 cmrr common mode rejection ratio* 55 ? ? db 300 300a t resp response time (1)* ?150400 600 ns ns pic16f87/88 pic16lf87/88 301 t mc 2 ov comparator mode change to output valid* ?? 10 s * these parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd ? 1.5)/2 while the other input transitions from v ss to v dd . operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c, unless otherwise stated spec no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? ? ? 1/2 1/2 lsb lsb low range (cvrr = 1 ) high range (cvrr = 0 ) d312 vr ur unit resistor value (r)* ? 2k ? ? 310 t set settling time (1) * ? ? 10 s * these parameters are characterized but not tested. note 1: settling time measured while cvrr = 1 and cvr<3:0> transitions from ? 0000 ? to ? 1111 ?.
pic16f87/88 ds30487c-page 178 ? 2005 microchip technology inc. 18.5 timing parameter symbology the timing parameter symbols have been created using one of the following formats: figure 18-3: load conditions 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osc2, but including portd and porte outputs as ports 15 pf for osc2 output load condition 1 load condition 2
? 2005 microchip technology inc. ds30487c-page 179 pic16f87/88 figure 18-4: external clock timing osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4 table 18-3: external clock timing requirements parameter no. sym characteristic min typ? max units conditions f osc external clki frequency (note 1) dc ? 1 mhz xt and rc oscillator mode dc ? 20 mhz hs oscillator mode dc ? 32 khz lp oscillator mode oscillator frequency (note 1) dc ? 4 mhz rc oscillator mode 0.1 ? 4 mhz xt oscillator mode 4 5 ? ? 20 200 mhz khz hs oscillator mode lp oscillator mode 1t osc external clki period (note 1) 1000 ? ? ns xt and rc oscillator modes 50 ? ? ns hs oscillator mode 5 ? ? ms lp oscillator mode oscillator period (note 1) 250 ? ? ns rc oscillator mode 250 ? 10,000 ns xt oscillator mode 50 ? 250 ns hs oscillator mode 5 ? ? ms lp oscillator mode 2t cy instruction cycle time (note 1) 200 t cy dc ns t cy = 4/f osc 3 tosl, to sh external clock in (osc1) high or low time 500 ? ? ns xt oscillator 2.5 ? ? ms lp oscillator 15 ? ? ns hs oscillator 4tosr, to sf external clock in (osc1) rise or fall time ? ? 25 ns xt oscillator ? ? 50 ns lp oscillator ? ? 15 ns hs oscillator ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices.
pic16f87/88 ds30487c-page 180 ? 2005 microchip technology inc. figure 18-5: clko and i/o timing table 18-4: clko and i/o timing requirements note: refer to figure 18-3 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value param no. symbol characteristic min typ? max units conditions 10* tosh2ckl osc1 to clko ? 75 200 ns (note 1) 11* tosh2ckh osc1 to clko ? 75 200 ns (note 1) 12* tckr clko rise time ? 35 100 ns (note 1) 13* tckf clko fall time ? 35 100 ns (note 1) 14* tckl2iov clko to port out valid ? ? 0.5 t cy + 20 ns (note 1) 15* tiov2ckh port in valid before clko t osc + 200 ? ? ns (note 1) 16* tckh2ioi port in hold after clko 0??ns (note 1) 17* tosh2iov osc1 (q1 cycle) to port out valid ? 100 255 ns 18* tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) pic16 f 87/88 100 ? ? ns pic16 lf 87/88 200 ? ? ns 19* tiov2osh port input valid to osc1 (i/o in setup time) 0 ? ? ns 20* t io r port output rise time pic16 f 87/88 ? 10 40 ns pic16 lf 87/88 ? ? 145 ns 21* t io f port output fall time pic16 f 87/88 ? 10 40 ns pic16 lf 87/88 ? ? 145 ns 22??* t inp int pin high or low time t cy ??ns 23??* t rbp rb7:rb4 change int high or low time t cy ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. ?? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode where clko output is 4 x t osc .
? 2005 microchip technology inc. ds30487c-page 181 pic16f87/88 figure 18-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 18-7: brown-out reset timing table 18-5: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements parameter no. sym characteristic min typ? max units conditions 30 tmcl mclr pulse width (low) 2 ? ? sv dd = 5v, -40c to +85c 31* t wdt watchdog timer time-out period (16-bit prescaler = 0100 and no postscaler) 13.6 16 18.4 ms v dd = 5v, -40c to +85c 32 t ost oscillation start-up timer period ? 1024 t osc ??t osc = osc1 period 33* t pwrt power-up timer period 61.2 72 82.8 ms v dd = 5v, -40c to +85c 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ??2.1 s 35 t bor brown-out reset pulse width 100 ? ? sv dd v bor (d005) * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. v dd mclr internal por pwrt time-out oscillator time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 18-3 for load conditions. v dd v bor 35
pic16f87/88 ds30487c-page 182 ? 2005 microchip technology inc. figure 18-8: timer0 and timer1 external clock timings table 18-6: timer0 and timer1 external clock requirements param no. symbol characteristic min typ? max units conditions 40* tt0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 41* tt0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 42* tt0p t0cki period no prescaler t cy + 40 ? ? ns with prescaler greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4, ..., 256) 45* tt1h t1cki high time synchronous, prescaler = 1 0.5 t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2, 4, 8 pic16 f 87/88 15 ? ? ns pic16 lf 87/88 25 ? ? ns asynchronous pic16 f 87/88 30 ? ? ns pic16 lf 87/88 50 ? ? ns 46* tt1l t1cki low time synchronous, prescaler = 1 0.5 t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2, 4, 8 pic16 f 87/88 15 ? ? ns pic16 lf 87/88 25 ? ? ns asynchronous pic16 f 87/88 30 ? ? ns pic16 lf 87/88 50 ? ? ns 47* tt1p t1cki input period synchronous pic16 f 87/88 greater of: 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) pic16 lf 87/88 greater of: 50 or t cy + 40 n n = prescale value (1, 2, 4, 8) asynchronous pic16 f 87/88 60 ? ? ns pic16 lf 87/88 100 ? ? ns ft1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) dc ? 32.768 khz 48 tckeztmr1 delay from external clock edge to timer increment 2 t osc ?7 t osc ? * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. note: refer to figure 18-3 for load conditions. 46 47 45 48 41 42 40 ra4/t0cki rb6/t1oso/t1cki tmr0 or tmr1
? 2005 microchip technology inc. ds30487c-page 183 pic16f87/88 figure 18-9: capture/compare/pwm timings (ccp1) table 18-7: capture/compare/pwm requirements (ccp1) note: refer to figure 18-3 for load conditions. ccp1 (capture mode) 50 51 52 53 54 ccp1 (compare or pwm mode) param no. symbol characteristic min typ? max units conditions 50* tccl ccp1 input low time no prescaler 0.5 t cy + 20 ? ? ns with prescaler pic16 f 87/88 10 ? ? ns pic16 lf 87/88 20 ? ? ns 51* tcch ccp1 input high time no prescaler 0.5 t cy + 20 ? ? ns with prescaler pic16 f 87/88 10 ? ? ns pic16 lf 87/88 20 ? ? ns 52* tccp ccp1 input period 3 t cy + 40 n ? ? ns n = prescale value (1, 4 or 16) 53* tccr ccp1 output rise time pic16 f 87/88 ? 10 25 ns pic16 lf 87/88 ? 25 50 ns 54* tccf ccp1 output fall time pic16 f 87/88 ? 10 25 ns pic16 lf 87/88 ? 25 45 ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested.
pic16f87/88 ds30487c-page 184 ? 2005 microchip technology inc. figure 18-10: spi? master mode timing (cke = 0 , smp = 0 ) figure 18-11: spi? master mode timing (cke = 1 , smp = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - -1 msb in lsb in bit 6 - - - -1 note: refer to figure 18-3 for load conditions. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 81 71 72 74 75, 76 78 80 msb 79 73 msb in bit 6 - - - - - -1 lsb in bit 6 - - - -1 lsb note: refer to figure 18-3 for load conditions.
? 2005 microchip technology inc. ds30487c-page 185 pic16f87/88 figure 18-12: spi? slave mode timing (cke = 0 ) figure 18-13: spi? slave mode timing (cke = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 77 78 79 80 79 78 sdi msb lsb bit 6 - - - - - -1 msb in bit 6 - - - -1 lsb in 83 note: refer to figure 18-3 for load conditions. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 71 72 82 sdi 74 75, 76 msb bit 6 - - - - - -1 lsb 77 msb in bit 6 - - - -1 lsb in 80 83 note: refer to figure 18-3 for load conditions. 70
pic16f87/88 ds30487c-page 186 ? 2005 microchip technology inc. table 18-8: spi? mode requirements figure 18-14: i 2 c? bus start/stop bits timing param no. symbol characteristic min typ? max units conditions 70* tssl2sch, tssl2scl ss to sck or sck input t cy ?? ns 71* tsch sck input high time (slave mode) t cy + 20 ? ? ns 72* tscl sck input low time (slave mode) t cy + 20 ? ? ns 73* tdiv2sch, tdiv2scl setup time of sdi data input to sck edge 100 ? ? ns 74* tsch2dil, tscl2dil hold time of sdi data input to sck edge 100 ? ? ns 75* tdor sdo data output rise time pic16 f 87/88 pic16 lf 87/88 ? ? 10 25 25 50 ns ns 76* tdof sdo data output fall time ? 10 25 ns 77* tssh2doz ss to sdo output high-impedance 10 ? 50 ns 78* tscr sck output rise time (master mode) pic16 f 87/88 pic16 lf 87/88 ? ? 10 25 25 50 ns ns 79* tscf sck output fall time (master mode) ? 10 25 ns 80* tsch2dov, tscl2dov sdo data output valid after sck edge pic16 f 87/88 pic16 lf 87/88 ? ? ? ? 50 145 ns ns 81* tdov2sch, tdov2scl sdo data output setup to sck edge t cy ?? ns 82* tssl2dov sdo data output valid after ss edge ? ? 50 ns 83* tsch2ssh, tscl2ssh ss after sck edge 1.5 t cy + 40 ? ? ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. note : refer to figure 18-3 for load conditions. 91 92 93 scl sda start condition stop condition 90
? 2005 microchip technology inc. ds30487c-page 187 pic16f87/88 table 18-9: i 2 c? bus start/stop bits requirements figure 18-15: i 2 c? bus data timing param no. symbol characteristic min typ max units conditions 90* t su : sta start condition 100 khz mode 4700 ? ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? ? 91* t hd : sta start condition 100 khz mode 4000 ? ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? ? 92* t su : sto stop condition 100 khz mode 4700 ? ? ns setup time 400 khz mode 600 ? ? 93 t hd : sto stop condition 100 khz mode 4000 ? ? ns hold time 400 khz mode 600 ? ? * these parameters are characterized but not tested. note: refer to figure 18-3 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
pic16f87/88 ds30487c-page 188 ? 2005 microchip technology inc. table 18-10: i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100* t high clock high time 100 khz mode 4.0 ? s 400 khz mode 0.6 ? s ssp module 1.5 t cy ? 101* t low clock low time 100 khz mode 4.7 ? s 400 khz mode 1.3 ? s ssp module 1.5 t cy ? 102* t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10-400 pf 103* t f sda and scl fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10-400 pf 90* t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91* t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? s 106* t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107* t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92* t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109* t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110* t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s c b bus capacitive loading ? 400 pf * these parameters are characterized but not tested. note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode (400 khz) i 2 c? bus device can be used in a standard mode (100 khz) i 2 c bus system, but the requirement, t su : dat 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the scl line is released.
? 2005 microchip technology inc. ds30487c-page 189 pic16f87/88 figure 18-16: ausart synchronous transmission (master/slave) timing table 18-11: ausart synchronous transmission requirements figure 18-17: ausart synchronous receive (master/slave) timing table 18-12: ausart synchronous receive requirements param no. sym characteristic min typ? max units conditions 120 tckh2dtv sync xmit (master & slave) clock high to data out valid pic16 f 87/88 ? ? 80 ns pic16 lf 87/88 ? ? 100 ns 121 tckrf clock out rise time and fall time (master mode) pic16 f 87/88 ? ? 45 ns pic16 lf 87/88 ? ? 50 ns 122 tdtrf data out rise time and fall time pic16 f 87/88 ? ? 45 ns pic16 lf 87/88 ? ? 50 ns ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameter s are for design guidance only and are not tested. param no. sym characteristic min typ? max units conditions 125 tdtv2ckl sync rcv (master & slave) data setup before ck (dt setup time) 15 ? ? ns 126 tckl2dtl data hold after ck (dt hold time) 15 ? ? ns ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 18-3 for load conditions. 121 121 122 rb5/ss /tx/ck rb2/sdo/rx/dt pin pin 120 note: refer to figure 18-3 for load conditions. 125 126 rb5/ss /tx/ck rb2/sdo/rx/dt pin pin
pic16f87/88 ds30487c-page 190 ? 2005 microchip technology inc. table 18-13: a/d converter characteristics: pic16f87/88 (industrial, extended) pic16lf87/88 (industrial) param no. sym characteristic min typ? max units conditions a01 n r resolution ? ? 10-bit bit v ref = v dd = 5.12v, v ss v ain v ref a03 e il integral linearity error ? ? <1 lsb v ref = v dd = 5.12v, v ss v ain v ref a04 e dl differential linearity error ? ? <1 lsb v ref = v dd = 5.12v, v ss v ain v ref a06 e off offset error ? ? <2 lsb v ref = v dd = 5.12v, v ss v ain v ref a07 e gn gain error ? ? <1 lsb v ref = v dd = 5.12v, v ss v ain v ref a10 ? monotonicity ? guaranteed (3) ??v ss v ain v ref a20 v ref reference voltage (v ref + ? v ref -) 2.0 ? v dd + 0.3 v a21 v ref + reference voltage high av dd ? 2.5v av dd + 0.3v v a22 v ref - reference voltage low av ss ? 0.3v v ref + ? 2.0v v a25 v ain analog input voltage v ss ? 0.3v ? v ref + 0.3v v a30 z ain recommended impedance of analog voltage source ??2.5k ? (note 4) a40 i ad a/d conversion current (v dd ) pic16f87/88 ? 220 ? a average current consumption when a/d is on (note 1) pic16lf87/88 ? 90 ? a a50 i ref v ref input current (note 2) ? ? ? ? 5 150 a a during v ain acquisition. based on differential of v hold to v ain to charge c hold , see section 12.1 ?a/d acquisition requirements? . during a/d conversion cycle * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. note 1: when a/d is off, it will not consume any current other t han minor leakage current. the power-down current specification includes any such leakage from the a/d module. 2: v ref current is from ra3 pin or v dd pin, whichever is selected as reference input. 3: the a/d conversion result never dec reases with an increase in the input voltage and has no missing codes. 4: maximum allowed impedance for analog voltage source is 10 k ?. this requires higher acquisition time.
? 2005 microchip technology inc. ds30487c-page 191 pic16f87/88 figure 18-18: a/d conversion timing table 18-14: a/d conversion requirements 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (t osc /2) (1) 987 210 note: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy . . . . . . param no. symbol characteristic min typ? max units conditions 130 t ad a/d clock period pic16f87/88 1.6 ? ? st osc based, v ref 3.0v pic16lf87/88 3.0 ? ? st osc based, v ref 2.0v pic16f87/88 2.0 4.0 6.0 s a/d rc mode pic16lf87/88 3.0 6.0 9.0 s a/d rc mode 131 t cnv conversion time (not including s/h time) (note 1) ?12t ad 132 t acq acquisition time (note 2) 10* 40 ? ? ? s s the minimum time is the amplifier settling time. this may be used if the ?new? input voltage has not changed by more than 1 lsb (i.e., 5.0 mv @ 5.12v) from the last sampled voltage (as stated on c hold ). 134 t go q4 to a/d clock start ? t osc /2 ? ? if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. this specification ensured by design. note 1: adres registers may be read on the following t cy cycle. 2: see section 12.1 ?a/d acquisition requirements? for minimum conditions.
pic16f87/88 ds30487c-page 192 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 193 pic16f87/88 19.0 dc and ac characteristics graphs and tables ?typical? represents the mean of the distribution at 25 c. ?maximum? or ?minimum? represents (mean + 3 ) or (mean ? 3 ) respectively, where is a standard deviation, over the whole temperature range. figure 19-1: typical i dd vs. f osc over v dd (hs mode) figure 19-2: maximum i dd vs. f osc over v dd (hs mode) note: the graphs and tables provided following this note are a statistical summary based on a limited number of samples and are provided for informational purposes only. the performance characteristics listed herein are not tested or guaranteed. in some graphs or tables, the data presented may be outside the specified operating range (e.g., outside specified power supply range) and therefore, outside the warranted range. 0 1 2 3 4 5 6 7 4 6 8 10 12 14 16 18 20 f osc (mhz) i dd (ma) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 1 2 3 4 5 6 7 8 4 6 8 10 12 14 16 18 20 f osc (mhz) i dd (ma) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 194 ? 2005 microchip technology inc. figure 19-3: typical i dd vs. f osc over v dd (xt mode) figure 19-4: maximum i dd vs. f osc over v dd (xt mode) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 0 500 1000 1500 2000 2500 3000 3500 4000 f osc (mhz) i dd (ma) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.5 1.0 1.5 2.0 2.5 0 500 1000 1500 2000 2500 3000 3500 4000 f osc (mhz) i dd (ma) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2005 microchip technology inc. ds30487c-page 195 pic16f87/88 figure 19-5: typical i dd vs. f osc over v dd (lp mode) figure 19-6: maximum i dd vs. f osc over v dd (lp mode) 0 10 20 30 40 50 60 70 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0 20 40 60 80 100 120 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 2.0v 2.5v 3.0v 3.5v 4.0v 4.5v 5.0v 5.5v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 196 ? 2005 microchip technology inc. figure 19-7: typical i dd vs. v dd , -40 c to +125 c, 1 mhz to 8 mhz (rc_run mode, all peripherals disabled) figure 19-8: maximum i dd vs. v dd , -40 c to +125 c, 1 mhz to 8 mhz (rc_run mode, all peripherals disabled) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.02.03.04.05.06.07.08.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 1.02.03.04.05.06.07.08.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2005 microchip technology inc. ds30487c-page 197 pic16f87/88 figure 19-9: i dd vs. v dd , sec_run mode, -10 c to +125 c, 32.768 khz (xtal 2 x 22 pf, all peripherals disabled) figure 19-10: i pd vs. v dd , -40 c to +125 c (sleep mode, all peripherals disabled) 0.0 5.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 2.02.53.03.54.04.55.05.5 vdd(v) idd( a) max (+70c) typ (+25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.001 0.01 0.1 1 10 100 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd (ua) typ (25c) max (85c) max (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 198 ? 2005 microchip technology inc. figure 19-11: average f osc vs. v dd for various values of r (rc mode, c = 20 pf, +25 c) figure 19-12: average f osc vs. v dd for various values of r (rc mode, c = 100 pf, +25 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 100 kohm 10 kohm 5.1 kohm operation above 4 mhz is not recommended 0.0 0.5 1.0 1.5 2.0 2.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 100 kohm 10 kohm 5.1 kohm 3.3 kohm
? 2005 microchip technology inc. ds30487c-page 199 pic16f87/88 figure 19-13: average f osc vs. v dd for various values of r (rc mode, c = 300 pf, +25 c) figure 19-14: ? i pd timer1 oscillator, -10c to +70c (sleep mode, tmr1 counter disabled) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 100 kohm 10 kohm 5.1 kohm 3.3 kohm ipd timer1 oscillator, -10c to +70c sleep mode, tmr1 counter disabled 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd ( a) typ (+25c) max (-10c to +70c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 200 ? 2005 microchip technology inc. figure 19-15: ? i pd wdt, -40c to +125c (sleep mode, all peripherals disabled) figure 19-16: ? i pd bor vs. v dd , -40c to +125c (sleep mode, bor enabled at 2.00v-2.16v) 0 2 4 6 8 10 12 14 16 18 2.02.53.03.54.04.55.05.5 v dd (v) ? i wdt ( a) max (-40c to +125c) max (-40c to +85c) typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 10 100 1,000 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i dd ( a) device in reset device in sleep indeterminant state max (125c) typ (25c) max (125c) typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) note: device current in reset depends on oscillator mode, frequency and circuit.
? 2005 microchip technology inc. ds30487c-page 201 pic16f87/88 figure 19-17: i pd a/d, -40 c to +125 c, sleep mode, a/d enabled (not converting) figure 19-18: typical, minimum and maximum v oh vs. i oh (v dd = 5v, -40 c to +125 c) 0 2 4 6 8 10 12 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) ? i a/d ( a) max (-40c to +125c) max (-40c to +85c) typ (+25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 0 5 10 15 20 25 i oh (-ma) v oh (v) max typ (25c) min typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 202 ? 2005 microchip technology inc. figure 19-19: typical, minimum and maximum v oh vs. i oh (v dd = 3v, -40 c to +125 c) figure 19-20: typical, minimum and maximum v ol vs. i ol (v dd = 5v, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 0 5 10 15 20 25 i oh (-ma) v oh (v) max typ (25c) min typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) max (85c) typ (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
? 2005 microchip technology inc. ds30487c-page 203 pic16f87/88 figure 19-21: typical, minimum and maximum v ol vs. i ol (v dd = 3v, -40 c to +125 c) figure 19-22: minimum and maximum v in vs. v dd (ttl input, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) max (85c) typ (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v th max (-40c) v th min (125c) v th typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c)
pic16f87/88 ds30487c-page 204 ? 2005 microchip technology inc. figure 19-23: minimum and maximum v in vs. v dd (st input, -40 c to +125 c) figure 19-24: minimum and maximum v in vs. v dd (i 2 c? input, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v ih max (125c) v ih min (-40c) v il max (-40c) v il min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) v ih max v ih min v il max v il min typical: statistical mean @ 25c maximum: mean + 3 (-40c to +125c) minimum: mean ? 3 (-40c to +125c) v il max
? 2005 microchip technology inc. ds30487c-page 205 pic16f87/88 figure 19-25: a/d nonlinearity vs. v refh (v dd = v refh , -40 c to +125 c) figure 19-26: a/d nonlinearity vs. v refh (v dd = 5v, -40 c to +125 c) 0 0.5 1 1.5 2 2.5 3 3.5 4 22.533.544.555.5 v dd and v refh (v) differential or integral nonlinearity (lsb) -40c 25c 85c 125c -40c +25c +85c +125c 0 0.5 1 1.5 2 2.5 3 22.533.544.555.5 v refh (v) differential or integral nonlinearilty (lsb) max (-40c to 125c) typ (25c) typ (+25c) max (-40c to +125c)
pic16f87/88 ds30487c-page 206 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 207 pic16f87/88 20.0 packaging information 20.1 package marking information 18-lead pdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic16f88-i/p 0510017 18-lead soic xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic16f88 -i/so 0510017 20-lead ssop xxxxxxxxxxx xxxxxxxxxxx yywwnnn example pic16f88 -i/ss 0510017 legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 16f88 -i/ml 0510017 3 e 3 e 3 e 3 e
pic16f87/88 ds30487c-page 208 ? 2005 microchip technology inc. 18-lead plastic dual in-line (p) ? 300 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 9.40 7.87 .430 .370 .310 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.46 1.14 .070 .058 .045 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 22.99 22.80 22.61 .905 .898 .890 d overall length 6.60 6.35 6.10 .260 .250 .240 e1 molded package width 8.26 7.94 7.62 .325 .313 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.68 3.30 2.92 .145 .130 .115 a2 molded package thickness 4.32 3.94 3.56 .170 .155 .140 a top to seating plane 2.54 .100 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches* units 1 2 d n e1 c eb e p a2 l b1 b a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-001 drawing no. c04-007 significant characteristic
? 2005 microchip technology inc. ds30487c-page 209 pic16f87/88 18-lead plastic small outline (so) ? wide, 300 mil body (soic) foot angle 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.30 0.27 0.23 .012 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 11.73 11.53 11.33 .462 .454 .446 d overall length 7.59 7.49 7.39 .299 .295 .291 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches* units l c h 45 1 2 d p n b e1 e a2 a1 a * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-013 drawing no. c04-051 significant characteristic
pic16f87/88 ds30487c-page 210 ? 2005 microchip technology inc. 20-lead plastic shrink small outline (ss) ? 209 mil body, 5.30 mm (ssop) 0.38 - 0.22 .015 - .009 b lead width 8 4 0 8 4 0 f foot angle 0.25 - 0.09 .010 - .004 c lead thickness 0.95 0.75 0.55 .037 .030 .022 l foot length 7.50 7.20 .295 .289 .283 .272 d overall length 5.60 5.30 5.00 .220 .209 .197 e1 molded package width 8.20 7.80 7.40 .323 .307 .291 e overall width - - 0.05 - - .002 a1 standoff 1.85 1.75 1.65 .073 .069 .065 a2 molded package thickness 2.00 - - .079 - - a overall height 0.65 .026 p pitch 20 20 n number of pins max nom min max nom min dimension limits millimeters* inches units 2 1 d p n b e e1 l c f a2 a a1 shall not exceed .010" (0.254mm) per side. dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions notes: jedec equivalent: mo-150 drawing no. c04-072 *controlling parameter revised 11/03/03
? 2005 microchip technology inc. ds30487c-page 211 pic16f87/88 28-lead plastic quad flat no lead package (ml) 6x6 mm body, punch singulated (qfn) lead width *controlling parameter drawing no. c04-114 notes: mold draft angle top dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010" (0.254mm) per side. b .009 12 .011 .014 0.23 12 0.28 0.35 pitch number of pins overall width standoff molded package length overall length molded package width molded package thickness overall height max units dimension limits a2 a1 e1 d d1 e n p a .026 .236 bsc .000 .226 bsc inches .026 bsc min 28 nom max 0.65 .031 .002 0.00 6.00 bsc 5.75 bsc millimeters* .039 min 28 0.65 bsc nom 0.80 0.05 1.00 .008 ref base thickness a3 0.20 ref jedec equivalent: mo-220 0.85 .033 .0004 0.01 .236 bsc .226 bsc 6.00 bsc 5.75 bsc lead length tie bar width l . 020 . 024 .030 0.50 0.60 0.75 r . 005 . 007 .010 0.13 0.17 0.23 tie bar length q .012 .016 .026 0.30 0.40 0.65 chamfer ch . 009 . 017 .024 0.24 0.42 0.60 e2 d2 exposed pad width exposed pad length .140 .146 .152 3.55 3.70 3.85 .140 .146 .152 3.55 3.70 3.85 d e e1 n 1 2 d1 a a2 exposed metal pad bottom view top view q l r p a1 a3 ch x 45 b d2 e2
pic16f87/88 ds30487c-page 212 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 213 pic16f87/88 appendix a: revision history revision a (november 2003) original data sheet for pic16f87/88 devices. revision b (august 2003) the specifications in section 18.0 ?electrical characteristics? have been updated to include the addition of maximum specifications to the dc characteristics tables, text clarification has been made to section 4.6.2 ?clock switching? and there have been minor updates to the data sheet text. revision c (january 2005) this revision includes the dc and ac characteristics graphs and tables. the electrical specifications in section 18.0 ?electrical characteristics? have been updated and there have been minor corrections to the data sheet text. appendix b: device differences the differences between the devices in this data sheet are listed in table b-1. table b-1: differences between the pic16f87 and pic16f88 features pic16f87 pic16f88 analog-to-digital converter n/a 10-bit, 7-channel
pic16f87/88 ds30487c-page 214 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. ds30487c-page 215 pic16f87/88 index a a/d acquisition requirements ........................................ 117 adif bit .................................................................... 116 analog-to-digital converter ...................................... 113 associated registers ............................................... 120 calculating acquisition time .................................... 117 configuring analog port pins ................................... 119 configuring the interrupt .......................................... 116 configuring the module ............................................ 116 conversion clock ..................................................... 118 conversions ............................................................. 119 converter characteristics ........................................ 190 delays ...................................................................... 117 effects of a reset ..................................................... 120 go/done bit ........................................................... 116 internal sampling switch (rss) impedance ............. 117 operation during sleep ........................................... 120 operation in power-managed modes ...................... 118 result registers ....................................................... 119 source impedance ................................................... 117 time delays ............................................................. 117 using the ccp trigger ............................................. 120 absolute maximum ratings ............................................. 163 ack .................................................................................... 93 adcon0 register ...................................................... 14, 113 adcon1 register ...................................................... 15, 113 addressable universal synchronous asynchronous receiver transmitter. see ausart. adresh register ...................................................... 14, 113 adresh, adresl register pair .................................... 116 adresl register ...................................................... 15, 113 ansel register ............................................. 15, 52, 58, 113 application notes an556 (implementing a table read) ........................ 25 an578 (use of the ssp module in the i 2 c multi-master environment) ................................. 87 an607 (power-up trouble shooting) ....................... 133 assembler mpasm assembler .................................................. 157 asynchronous reception associated registers ....................................... 105, 107 asynchronous transmission associated registers ............................................... 103 ausart ............................................................................ 97 address detect enable (adden bit) ......................... 98 asynchronous mode ................................................ 102 asynchronous receive (9-bit mode) ........................ 106 asynchronous receive with address detect. see asynchronous receive (9-bit mode). asynchronous receiver ........................................... 104 asynchronous reception ......................................... 105 asynchronous transmitter ....................................... 102 baud rate generator (brg) ...................................... 99 baud rate formula ............................................ 99 baud rates, asynchronous mode (brgh = 0) .............................................. 100 baud rates, asynchronous mode (brgh = 1) .............................................. 100 high baud rate select (brgh bit) ................... 97 intrc baud rates, asynchronous mode (brgh = 0) .............................................. 101 intrc baud rates, asynchronous mode (brgh = 1) .............................................. 101 intrc operation ............................................... 99 low-power mode operation .............................. 99 sampling ........................................................... 99 clock source select (csrc bit) ............................... 97 continuous receive enable (cren bit) ................... 98 framing error (ferr bit) .......................................... 98 mode select (sync bit) ............................................ 97 receive data, 9th bit (rx9d bit) ............................... 98 receive enable, 9-bit (rx9 bit) ................................. 98 serial port enable (spen bit) ............................. 97, 98 single receive enable (sren bit) ............................ 98 synchronous master mode ...................................... 108 synchronous master reception .............................. 110 synchronous master transmission ......................... 108 synchronous slave mode ........................................ 111 synchronous slave reception ................................ 112 synchronous slave transmit ................................... 111 transmit data, 9th bit (tx9d) ................................... 97 transmit enable (txen bit) ...................................... 97 transmit enable, nine-bit (tx9 bit) ........................... 97 transmit shift register status (trmt bit) ......................................................... 97 b baud rate generator associated registers ................................................. 99 bf bit ................................................................................. 93 block diagrams a/d ........................................................................... 116 analog input model .......................................... 117, 125 ausart receive ............................................ 104, 106 ausart transmit ................................................... 102 capture mode operation ........................................... 82 comparator i/o operating modes ........................... 122 comparator output .................................................. 124 comparator voltage reference ............................... 128 compare mode operation ......................................... 83 fail-safe clock monitor ........................................... 144 in-circuit serial programming connections .................................................... 147 interrupt logic .......................................................... 139 on-chip reset circuit .............................................. 132 pic16f87 .................................................................... 6 pic16f88 .................................................................... 7 ra0/an0:ra1/an1 pins ............................................ 52 ra2/an2/cv ref /v ref - pin ....................................... 53 ra3/an3/v ref +/c1out pin ..................................... 53 ra4/an4/t0cki/c2out pin ..................................... 54 ra5/mclr /v pp pin ................................................... 54 ra6/osc2/clko pin ................................................ 55 ra7/osc1/clki pin .................................................. 56 rb0/int/ccp1 pin .................................................... 59 rb1/sdi/sda pin ...................................................... 60 rb2/sdo/rx/dt pin ................................................. 61 rb3/pgm/ccp1 pin .................................................. 62 rb4/sck/scl pin ..................................................... 63 rb5/ss /tx/ck pin .................................................... 64
pic16f87/88 ds30487c-page 216 ? 2005 microchip technology inc. rb6/an5/pgc/t1oso/t1cki pin ............................. 65 rb7/an6/pgd/t1osi pin .......................................... 66 simplified pwm .......................................................... 84 ssp in i 2 c mode ........................................................ 92 ssp in spi mode ....................................................... 90 system clock ............................................................. 41 timer0/wdt prescaler .............................................. 67 timer1 ........................................................................ 73 timer2 ........................................................................ 79 watchdog timer (wdt) ........................................... 141 bor. see brown-out reset. brgh bit ............................................................................ 99 brown-out reset (bor) ........................... 129, 132, 133, 135 bor status (bor bit) ................................................ 24 c c compilers mplab c17 ............................................................. 158 mplab c18 ............................................................. 158 mplab c30 ............................................................. 158 capture/compare/pwm (ccp) .......................................... 81 capture mode ............................................................ 82 ccp pin configuration ....................................... 82 software interrupt .............................................. 82 timer1 mode selection ...................................... 82 capture, compare and timer1 associated registers ......................................... 83 ccp prescaler ........................................................... 82 ccp timer resources ............................................... 81 ccp1if ...................................................................... 82 ccpr1 ....................................................................... 82 ccpr1h:ccpr1l ..................................................... 82 compare mode .......................................................... 83 ccp pin configuration ....................................... 83 software interrupt mode .................................... 83 special event trigger ......................................... 83 special event trigger output of ccp1 .............. 83 timer1 mode selection ...................................... 83 pwm and timer2 associated registers .................... 85 pwm mode ................................................................ 84 example frequencies/resolutions .................... 85 operation setup ................................................. 85 ccp1con register ........................................................... 14 ccp1m0 bit ....................................................................... 81 ccp1m1 bit ....................................................................... 81 ccp1m2 bit ....................................................................... 81 ccp1m3 bit ....................................................................... 81 ccp1x bit .......................................................................... 81 ccp1y bit .......................................................................... 81 ccpr1h register ........................................................ 14, 81 ccpr1l register ......................................................... 14, 81 clock sources .................................................................... 39 selection using osccon register ........................... 39 clock switching .................................................................. 39 transition and the watchdog timer ........................... 40 transition sequence .................................................. 41 cmcon register ............................................................... 15 code examples call of a subroutine in page 1 from page 0 ............... 25 changing between capture prescalers ..................... 82 changing prescaler assignment from wdt to timer0 ................................................... 69 erasing a flash program memory row ..................... 31 implementing a real-time clock using a timer1 interrupt service ................................. 77 indirect addressing .................................................... 26 initializing porta ...................................................... 51 reading a 16-bit free running timer ....................... 74 reading data eeprom ............................................ 29 reading flash program memory ............................... 30 saving status, w and pclath registers in ram ............................................................. 140 writing a 16-bit free running timer ......................... 74 writing to data eeprom .......................................... 29 writing to flash program memory ............................. 33 code protection ....................................................... 129, 147 comparator module ......................................................... 121 analog input connection considerations ................ 125 associated registers ............................................... 126 configuration ........................................................... 122 effects of a reset .................................................... 125 external reference signal ....................................... 123 internal reference signal ........................................ 123 interrupts ................................................................. 124 operation ................................................................. 123 operation during sleep ........................................... 125 outputs .................................................................... 123 reference ................................................................ 123 response time ........................................................ 123 comparator specifications ............................................... 177 comparator voltage reference ....................................... 127 associated registers ............................................... 128 computed goto ............................................................... 25 configuration bits ............................................................ 129 crystal and ceramic resonators ....................................... 35 customer change notification service ............................ 223 customer notification service ......................................... 223 customer support ............................................................ 223 cvrcon register ............................................................. 15 d data eeprom memory ..................................................... 27 associated registers ................................................. 34 eeadr register ........................................................ 27 eeadrh register ..................................................... 27 eecon1 register ...................................................... 27 eecon2 register ...................................................... 27 eedata register ...................................................... 27 eedath register ...................................................... 27 operation during code-protect ................................. 34 protection against spurious writes ........................... 34 reading ..................................................................... 29 write complete flag (eeif bit) ................................. 27 writing ....................................................................... 29 data memory special function registers ........................................ 14 dc and ac characteristics graphs and tables .................................................. 193 dc characteristics internal rc accuracy ............................................... 174 pic16f87/88, pic16lf87/88 .................................. 175 power-down and supply current ............................ 166 supply voltage ........................................................ 165 demonstration boards picdem 1 ................................................................ 160 picdem 17 .............................................................. 161 picdem 18r ........................................................... 161 picdem 2 plus ........................................................ 160 picdem 3 ................................................................ 160 picdem 4 ................................................................ 160 picdem lin ............................................................ 161 picdem usb .......................................................... 161 picdem.net internet/ethernet ................................. 160
? 2005 microchip technology inc. ds30487c-page 217 pic16f87/88 development support ...................................................... 157 device differences ........................................................... 213 device overview .................................................................. 5 direct addressing ............................................................... 26 e eeadr register .......................................................... 16, 27 eeadrh register ........................................................ 16, 27 eecon1 register ........................................................ 16, 27 eecon2 register ........................................................ 16, 27 eedata register ........................................................ 16, 27 eedath register ........................................................ 16, 27 electrical characteristics .................................................. 163 errata ................................................................................... 4 evaluation and programming tools ................................. 161 exiting sleep with an interrupt ........................................... 50 external clock input ........................................................... 36 external clock input (ra4/t0cki). see timer0. external interrupt input (rb0/int). see interrupt sources. f fail-safe clock monitor ............................................ 129, 144 flash program memory ..................................................... 27 associated registers ................................................. 34 eeadr register ........................................................ 27 eeadrh register ...................................................... 27 eecon1 register ...................................................... 27 eecon2 register ...................................................... 27 eedata register ...................................................... 27 eedath register ...................................................... 27 erasing ....................................................................... 30 reading ...................................................................... 30 writing ........................................................................ 32 fsr register ......................................................... 14, 15, 26 g general purpose register file ........................................... 12 i i/o ports ............................................................................. 51 porta ....................................................................... 51 portb ....................................................................... 57 trisb register .......................................................... 57 i 2 c addressing ................................................................. 93 associated registers ................................................. 95 master mode .............................................................. 95 mode .......................................................................... 92 mode selection .......................................................... 92 multi-master mode ..................................................... 95 reception ................................................................... 93 scl and sda pins ..................................................... 93 slave mode ................................................................ 93 transmission .............................................................. 93 id locations ............................................................. 129, 147 in-circuit debugger .......................................................... 147 in-circuit serial programming .......................................... 129 in-circuit serial programming (icsp) .............................. 147 indf register ........................................................ 14, 15, 26 indirect addressing ............................................................ 26 instruction set .................................................................. 149 addlw .................................................................... 151 addwf ................................................................... 151 andlw .................................................................... 151 andwf ................................................................... 151 bcf ......................................................................... 151 bsf .......................................................................... 151 btfsc ..................................................................... 152 btfss ..................................................................... 152 call ........................................................................ 152 clrf ....................................................................... 152 clrw ...................................................................... 152 clrwdt ................................................................. 152 comf ...................................................................... 153 decf ....................................................................... 153 decfsz .................................................................. 153 descriptions ............................................................. 151 general format ....................................................... 149 goto ...................................................................... 153 incf ........................................................................ 153 incfsz .................................................................... 153 iorlw ..................................................................... 154 iorwf ..................................................................... 154 movf ...................................................................... 154 movlw ................................................................... 154 movwf ................................................................... 154 nop ......................................................................... 154 read-modify-write operations ................................ 149 retfie .................................................................... 155 retlw .................................................................... 155 return .................................................................. 155 rlf .......................................................................... 155 rrf ......................................................................... 155 sleep ..................................................................... 155 sublw .................................................................... 156 subwf .................................................................... 156 summary table ....................................................... 150 swapf .................................................................... 156 xorlw ................................................................... 156 xorwf ................................................................... 156 int interrupt (rb0/int). see interrupt sources. intcon register gie bit ....................................................................... 19 int0ie bit .................................................................. 19 int0if bit .................................................................. 19 peie bit ..................................................................... 19 rbie bit ..................................................................... 19 rbif bit ..................................................................... 19 tmr0ie bit ................................................................ 19 internal oscillator block ..................................................... 37 intrc modes ............................................................ 38 internet address .............................................................. 223 interrupt sources ..................................................... 129, 138 ausart receive/transmit complete ....................... 97 rb0/int pin, external ............................................. 140 tmr0 overflow ........................................................ 140 interrupts rb7:rb4 port change .............................................. 57 interrupts, context saving during .................................... 140
pic16f87/88 ds30487c-page 218 ? 2005 microchip technology inc. interrupts, enable bits a/d converter interrupt enable (adie bit) ................. 20 ausart receive interrupt enable (rcie bit) ........... 20 ausart transmit interrupt enable (txie bit) .......... 20 ccp1 interrupt enable (ccp1ie bit) ......................... 20 comparator interrupt enable (cmie bit) .................... 22 eeprom write operation interrupt enable (eeie bit) ............................................... 22 global interrupt enable (gie bit) ....................... 19, 138 interrupt-on-change (rb7:rb4) enable (rbie bit) ............................................. 140 oscillator fail interrupt enable (osfie bit) ............... 22 peripheral interrupt enable (peie bit) ....................... 19 port change interrupt enable (rbie bit) ................... 19 rb0/int enable (int0ie bit) ..................................... 19 synchronous serial port (ssp) interrupt enable (sspie bit) .............................. 20 tmr0 overflow enable (tmr0ie bit) ........................ 19 tmr1 overflow interrupt enable (tmr1ie bit) ...................................................... 20 tmr2 to pr2 match interrupt enable (tmr2ie bit) ...................................................... 20 interrupts, flag bits a/d converter interrupt flag (adif bit) ..................... 21 ausart receive interrupt flag (rcif bit) ............... 21 ausart transmit interrupt flag (txif bit) ............... 21 ccp1 interrupt flag (ccp1if bit) .............................. 21 comparator interrupt flag (cmif bit) ........................ 23 eeprom write operation interrupt flag (eeif bit) ................................................... 23 interrupt-on-change (rb7:rb4) flag (rbif bit) ........................................... 19, 140 oscillator fail interrupt flag (osfif bit) .................... 23 rb0/int flag (int0if bit) .......................................... 19 synchronous serial port (ssp) interrupt flag (sspif bit) ................................................. 21 tmr0 overflow flag (tmr0if bit) .......................... 140 tmr1 overflow interrupt flag (tmr1if bit) .............. 21 tmr2 to pr2 interrupt flag (tmr2if bit) ................. 21 intrc modes adjustment ................................................................. 38 l loading of pc .................................................................... 25 low-voltage icsp programming ..................................... 148 m master clear (mclr ) mclr reset, normal operation ...................... 132, 135 mclr reset, sleep ......................................... 132, 135 operation and esd protection ................................. 133 memory organization ......................................................... 11 data memory ............................................................. 11 program memory ....................................................... 11 microchip internet web site ............................................. 223 mplab asm30 assembler, linker, librarian .................. 158 mplab icd 2 in-circuit debugger ................................... 159 mplab ice 2000 high-performance universal in-circuit emulator ................................... 159 mplab ice 4000 high-performance universal in-circuit emulator ................................... 159 mplab integrated development environment software .............................................. 157 mplab pm3 device programmer .................................... 159 mplink object linker/mplib object librarian ............... 158 o opcode field descriptions ............................................... 149 option_reg register intedg bit ................................................................ 18 ps2:ps0 bits ............................................................. 18 psa bit ...................................................................... 18 rbpu bit ................................................................... 18 t0cs bit .................................................................... 18 t0se bit .................................................................... 18 osccon register ............................................................. 15 oscillator configuration ..................................................... 35 ecio .......................................................................... 35 extrc .................................................................... 134 hs ...................................................................... 35, 134 intio1 ....................................................................... 35 intio2 ....................................................................... 35 intrc ...................................................................... 134 lp ...................................................................... 35, 134 rc ....................................................................... 35, 37 rcio .......................................................................... 35 xt ...................................................................... 35, 134 oscillator control register modifying ircf bits ................................................... 41 oscillator delay upon power-up, wake-up and clock switching .................................................. 42 oscillator start-up timer (ost) .... ........................... 129, 133 oscillator switching ........................................................... 39 osctune register ........................................................... 15 p packaging information ..................................................... 207 marking .................................................................... 207 paging, program memory .................................................. 25 pcl register ......................................................... 14, 15, 25 pclath register .................................................. 14, 15, 25 pcon register .......................................................... 15, 134 bor bit ...................................................................... 24 por bit ...................................................................... 24 pickit 1 flash starter kit ................................................. 161 picstart plus development programmer .................... 160 pie1 register ..................................................................... 15 adie bit ..................................................................... 20 ccp1ie bit ................................................................ 20 rcie bit ..................................................................... 20 sspie bit ................................................................... 20 tmr1ie bit ................................................................ 20 tmr2ie bit ................................................................ 20 txie bit ..................................................................... 20 pie2 register ..................................................................... 15 cmie bit .................................................................... 22 eeie bit ..................................................................... 22 osfie bit ................................................................... 22 pinout descriptions pic16f87/88 ............................................................... 8 pir1 register .................................................................... 14 adif bit ..................................................................... 21 ccp1if bit ................................................................. 21 rcif bit ..................................................................... 21 sspif bit ................................................................... 21 tmr1if bit ................................................................. 21 tmr2if bit ................................................................. 21 txif bit ...................................................................... 21
? 2005 microchip technology inc. ds30487c-page 219 pic16f87/88 pir2 register ..................................................................... 14 cmif bit ..................................................................... 23 eeif bit ...................................................................... 23 osfif bit ................................................................... 23 pop ................................................................................... 25 por. see power-on reset. porta ................................................................................. 8 associated register summary ................................... 52 porta register ................................................................ 14 portb ................................................................................. 9 associated register summary ................................... 58 portb register .................................................. 14, 16 pull-up enable (rbpu bit) ......................................... 18 rb0/int edge select (intedg bit) ........................... 18 rb0/int pin, external .............................................. 140 rb2/sdo/rx/dt pin ........................................... 98, 99 rb5/ss /tx/ck pin .................................................... 98 rb7:rb4 interrupt-on-change ................................. 140 rb7:rb4 interrupt-on-change enable (rbie bit) ............................................. 140 rb7:rb4 interrupt-on-change flag (rbif bit) ........................................... 19, 140 trisb register .......................................................... 97 postscaler, wdt assignment (psa bit) ................................................ 18 rate select (ps2:ps0 bits) ....................................... 18 power-down mode. see sleep. power-managed modes ..................................................... 43 rc_run .................................................................... 43 sec_run .................................................................. 44 sec_run/rc_run to primary clock source .......... 45 power-on reset (por) ............................ 129, 132, 133, 135 por status (por bit) ................................................ 24 power control (pcon) register .............................. 134 power-down (pd bit) ............................................... 132 time-out (to bit) ............................................... 17, 132 power-up timer (pwrt) ......................................... 129, 133 pr2 register ................................................................ 15, 79 prescaler, timer0 assignment (psa bit) ................................................ 18 rate select (ps2:ps0 bits) ....................................... 18 pro mate ii universal device programmer .................. 159 program counter reset conditions ...................................................... 135 program memory interrupt vector .......................................................... 11 map and stack pic16f87/88 ...................................................... 11 paging ........................................................................ 25 reset vector .............................................................. 11 program verification ........................................................ 147 push ................................................................................. 25 r r/w bit ............................................................................... 93 ra0/an0 pin ........................................................................ 8 ra1/an1 pin ........................................................................ 8 ra2/an2/cv ref /v ref - pin .................................................. 8 ra3/an3/v ref +/c1out pin ............................................... 8 ra4/an4/t0cki/c2out pin ............................................... 8 ra5/mclr /v pp pin ............................................................. 8 ra6/osc2/clko pin .......................................................... 8 ra7/osc1/clki pin ............................................................ 8 rb0/int/ccp1 pin .............................................................. 9 rb1/sdi/sda pin ................................................................ 9 rb2/sdo/rx/dt pin ........................................................... 9 rb3/pgm/ccp1 pin ............................................................ 9 rb4/sck/scl pin ............................................................... 9 rb5/ss /tx/ck pin .............................................................. 9 rb6/an5/pgc/t1oso/t1cki pin ...................................... 9 rb7/an6/pgd/t1osi pin ................................................... 9 rbif bit ............................................................................. 57 rcio oscillator .................................................................. 37 rcreg register ............................................................... 14 rcsta register ................................................................ 14 adden bit ................................................................. 98 cren bit ................................................................... 98 ferr bit .................................................................... 98 rx9 bit ...................................................................... 98 rx9d bit .................................................................... 98 spen bit .............................................................. 97, 98 sren bit ................................................................... 98 reader response ............................................................ 224 receive overflow indicator bit, sspov ............................ 89 register file map pic16f87 .................................................................. 12 pic16f88 .................................................................. 13 registers adcon0 (a/d control 0) ......................................... 114 adcon1 (a/d control 1) ......................................... 115 ansel (analog select) ........................................... 113 ccp1con (capture/compare/pwm control 1) ........................................................... 81 cmcon (comparator control) ................................ 121 config1 (configuration word 1) ........................... 130 config2 (configuration word 2) ........................... 131 cvrcon (comparator voltage reference control) .......................................... 127 eecon1 (data eeprom access control 1) ............ 28 fsr ........................................................................... 26 initialization conditions (table) ......................... 135?136 intcon (interrupt control) ....................................... 19 option_reg (option control) .......................... 18, 68 osccon (oscillator control) .................................... 40 osctune (oscillator tuning) ................................... 38 pcon (power control) .............................................. 24 pie1 (peripheral interrupt enable 1) ......................... 20 pie2 (peripheral interrupt enable 2) ......................... 22 pir1 (peripheral interrupt request (flag) 1) ............. 21 pir2 (peripheral interrupt request (flag) 2) ............. 23 rcsta (receive status and control) ....................... 98 special function, summary ....................................... 14 sspcon (synchronous serial port control) ............. 89 sspstat (synchronous serial port status) ............. 88 status (arithmetic status) ...................................... 17 t1con (timer1 control) ........................................... 72 t2con (timer2 control) ........................................... 80 txsta (transmit status and control) ....................... 97 wdtcon (watchdog timer control) ...................... 142 reset ....................................................................... 129, 132 brown-out reset (bor). see brown-out reset (bor). mclr reset. see mclr . power-on reset (por). see power-on reset (por). reset conditions for all registers ........................... 135 reset conditions for pcon register ...................... 135 reset conditions for program counter ................... 135 reset conditions for status register .................. 135 wdt reset. see watchdog timer (wdt). revision history ............................................................... 213 rp0 bit .............................................................................. 11 rp1 bit .............................................................................. 11
pic16f87/88 ds30487c-page 220 ? 2005 microchip technology inc. s sci. see ausart. scl .................................................................................... 93 serial communication interface. see ausart. slave mode scl ............................................................................ 93 sda ............................................................................ 93 sleep ................................................................ 129, 132, 145 software simulator (mplab sim) .................................... 158 software simulator (mplab sim30) ................................ 158 spbrg register ................................................................ 15 special event trigger ....................................................... 120 special features of the cpu ............................................ 129 special function registers ................................................ 14 special function registers (sfrs) .................................... 14 spi associated registers ................................................. 90 serial clock ................................................................ 87 serial data in ............................................................. 87 serial data out .......................................................... 87 slave select ............................................................... 87 ssp ack ............................................................................ 93 i 2 c i 2 c operation ..................................................... 92 sspadd register .............................................................. 15 sspbuf register .............................................................. 14 sspcon register .............................................................. 14 sspov ............................................................................... 89 sspov bit .......................................................................... 93 sspstat register ............................................................ 15 stack .................................................................................. 25 overflows ................................................................... 25 underflow ................................................................... 25 status register c bit ........................................................................... 17 dc bit ......................................................................... 17 irp bit ........................................................................ 17 pd bit ................................................................. 17, 132 rp bits ....................................................................... 17 to bit ................................................................. 17, 132 z bit ............................................................................ 17 synchronous master reception associated registers ............................................... 110 synchronous master transmission associated registers ............................................... 109 synchronous serial port (ssp) .......................................... 87 overview .................................................................... 87 spi mode ................................................................... 87 synchronous slave reception associated registers ............................................... 112 synchronous slave transmission associated registers ............................................... 111 t t1ckps0 bit ...................................................................... 72 t1ckps1 bit ...................................................................... 72 t1con register ................................................................. 14 t1oscen bit ..................................................................... 72 t1sync bit ........................................................................ 72 t2ckps0 bit ...................................................................... 80 t2ckps1 bit ...................................................................... 80 t2con register ................................................................. 14 t ad ................................................................................... 118 time-out sequence .......................................................... 134 timer0 ................................................................................ 67 associated registers ................................................. 69 clock source edge select (t0se bit) ....................... 18 clock source select (t0cs bit) ................................. 18 external clock ............................................................ 68 interrupt ..................................................................... 67 operation ................................................................... 67 overflow enable (tmr0ie bit) ................................... 19 overflow flag (tmr0if bit) ..................................... 140 overflow interrupt .................................................... 140 prescaler ................................................................... 68 t0cki ........................................................................ 68 timer1 ................................................................................ 71 associated registers ................................................. 77 capacitor selection .................................................... 75 counter operation ..................................................... 73 operation ................................................................... 71 operation in asynchronous counter mode ................ 74 reading and writing .......................................... 74 operation in synchronized counter mode ................. 73 operation in timer mode ........................................... 73 oscillator .................................................................... 75 oscillator layout considerations ............................... 75 prescaler ................................................................... 76 resetting timer1 register pair .................................. 76 resetting timer1 using a ccp trigger output ......... 76 use as a real-time clock ......................................... 76 timer2 ................................................................................ 79 associated registers ................................................. 80 output ........................................................................ 79 postscaler .................................................................. 79 prescaler ................................................................... 79 prescaler and postscaler ........................................... 79 timing diagrams a/d conversion ........................................................ 191 asynchronous master transmission ........................ 103 asynchronous master transmission (back to back) ................................................. 103 asynchronous reception ......................................... 104 asynchronous reception with address byte first ........................................... 107 asynchronous reception with address detect ................................................ 107 ausart synchronous receive (master/slave) ................................................. 189 ausart synchronous transmission (master/slave) ................................................. 189 brown-out reset ...................................................... 181 capture/compare/pwm (ccp1) ............................. 183 clko and i/o .......................................................... 180 external clock .......................................................... 179 fail-safe clock monitor ........................................... 144 i 2 c bus data ............................................................ 187 i 2 c bus start/stop bits ............................................ 186 i 2 c reception (7-bit address) ................................... 94 i 2 c transmission (7-bit address) .............................. 94 primary system clock after reset (ec, rc, intrc) ............................................... 48 primary system clock after reset (hs, xt, lp) ...................................................... 47 pwm output .............................................................. 84 reset, watchdog timer, oscillator start-up timer and power-up timer .............................. 181 slow rise time (mclr tied to v dd through rc network) ...................................... 138
? 2005 microchip technology inc. ds30487c-page 221 pic16f87/88 spi master mode ....................................................... 91 spi master mode (cke = 0, smp = 0) .................... 184 spi master mode (cke = 1, smp = 1) .................... 184 spi slave mode (cke = 0) ................................ 91, 185 spi slave mode (cke = 1) ................................ 91, 185 switching to sec_run mode ................................... 44 synchronous reception (master mode, sren) ..................................... 111 synchronous transmission ...................................... 109 synchronous transmission (through txen) .......... 109 time-out sequence on power-up (mclr tied to v dd through pull-up resistor) ............ 137 time-out sequence on power-up (mclr tied to v dd through rc network): case 1 ..... 137 time-out sequence on power-up (mclr tied to v dd through rc network): case 2 ..... 137 timer0 and timer1 external clock .......................... 182 timer1 incrementing edge ......................................... 73 transition between sec_run/rc_run and primary clock ............................................. 46 two-speed start-up mode ....................................... 143 wake-up from sleep via interrupt ............................ 146 xt, hs, lp, ec and extrc to rc_run mode .................................................. 43 timing parameter symbology .......................................... 178 timing requirements a/d conversion ........................................................ 191 ausart synchronous receive .............................. 189 ausart synchronous transmission ...................... 189 capture/compare/pwm (ccp1) .............................. 183 clko and i/o .......................................................... 180 external clock .......................................................... 179 i 2 c bus data ............................................................ 188 i 2 c bus start/stop bits ............................................. 187 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset ............ 181 spi mode ................................................................. 186 timer0 and timer1 external clock .......................... 182 tmr0 register ............................................................. 14, 16 tmr1cs bit ....................................................................... 72 tmr1h register ................................................................ 14 tmr1l register ................................................................. 14 tmr1on bit ...................................................................... 72 tmr2 register ................................................................... 14 tmr2on bit ...................................................................... 80 toutps0 bit ..................................................................... 80 toutps1 bit ..................................................................... 80 toutps2 bit ..................................................................... 80 toutps3 bit ..................................................................... 80 trisa register ............................................................ 15, 51 trisb register ............................................................ 15, 16 two-speed clock start-up mode ..................................... 143 two-speed start-up ......................................................... 129 txreg register ................................................................ 14 txsta register ................................................................. 15 brgh bit ................................................................... 97 csrc bit ................................................................... 97 sync bit ................................................................... 97 trmt bit ................................................................... 97 tx9 bit ....................................................................... 97 tx9d bit .................................................................... 97 txen bit .................................................................... 97 v v dd pin ................................................................................ 9 voltage reference specifications .................................... 177 v ss pin ................................................................................ 9 w wake-up from sleep ................................................ 129, 146 interrupts ................................................................. 135 mclr reset ............................................................ 135 wdt reset .............................................................. 135 wake-up using interrupts ................................................ 146 watchdog timer (wdt) ........................................... 129, 141 associated registers ............................................... 142 wdt reset, normal operation ........................ 132, 135 wdt reset, sleep ........................................... 132, 135 wcol ................................................................................ 89 wdtcon register ............................................................ 16 write collision detect bit, wcol ...................................... 89 www address ................................................................ 223 www, on-line support ................... ................................... 4
pic16f87/88 ds30487c-page 222 ? 2005 microchip technology inc. notes:
? 2005 microchip technology inc. advance information ds30487c-page 223 pic16f87/88 the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information:  product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software  general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing  business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels:  distributor or representative  local sales office  field application engineer (fae)  technical support  development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com in addition, there is a development systems information line which lists the latest versions of microchip?s development systems software products. this line also provides information on how customers can receive currently available upgrade kits. the development systems information line numbers are: 1-800-755-2345 ? united states and most of canada 1-480-792-7302 ? other international locations
pic16f87/88 ds30487c-page 224 advance information ? 2005 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds30487c pic16f87/88 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2005 microchip technology inc. ds30487c-page 225 pic16f87/88 pic16f87/88 product identification system to order or obtain information, e.g. , on pricing or delivery, refer to the factory or the listed sales office. part no. x /xx xxx pattern package temperature range device device pic16f87: standard v dd range pic16f87t: (tape and reel) pic16lf87: extended v dd range temperature range - = 0c to +70c i = -40c to +85c (industrial) e = -40c to +125c (extended) package p = pdip so = soic ss = ssop ml = qfn pattern qtp, sqtp, rom code (factory specified) or special requirements. blank for otp and windowed devices. examples: a) pic16f87-i/p = industrial temp., pdip package, extended v dd limits. b) pic16f87-i/so = industrial temp., soic package, normal v dd limits. note 1: f = cmos flash lf = low-power cmos flash 2: t = in tape and reel ? soic, ssop packages only.
ds30487c-page 226 ? 2005 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta alpharetta, ga tel: 770-640-0034 fax: 770-640-0307 boston westford, ma tel: 978-692-3848 fax: 978-692-3821 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 san jose mountain view, ca tel: 650-215-1444 fax: 650-961-0286 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8676-6200 fax: 86-28-8676-6599 china - fuzhou tel: 86-591-8750-3506 fax: 86-591-8750-3521 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - shunde tel: 86-757-2839-5507 fax: 86-757-2839-5571 china - qingdao tel: 86-532-502-7355 fax: 86-532-502-7205 asia/pacific india - bangalore tel: 91-80-2229-0061 fax: 91-80-2229-0062 india - new delhi tel: 91-11-5160-8631 fax: 91-11-5160-8632 japan - kanagawa tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 taiwan - hsinchu tel: 886-3-572-9526 fax: 886-3-572-6459 europe austria - weis tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark - ballerup tel: 45-4450-2828 fax: 45-4485-2829 france - massy tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - ismaning tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 england - berkshire tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 10/20/04


▲Up To Search▲   

 
Price & Availability of PIC16F87-EML

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X